Fixed merge issues

This commit is contained in:
Eduardo Flores 2022-12-06 12:37:36 -07:00
parent 8e6959a3cb
commit 375428b4a8
5 changed files with 167 additions and 118 deletions

View file

@ -9,7 +9,7 @@ use cosmic::{
iced_lazy::responsive, iced_lazy::responsive,
iced_winit::window::{drag, toggle_maximize, minimize}, iced_winit::window::{drag, toggle_maximize, minimize},
theme::{self, Theme}, theme::{self, Theme},
widget::{button, nav_button, nav_bar, header_bar, settings, scrollable, toggler}, widget::{button, nav_button, nav_bar, header_bar, settings, scrollable, toggler, nav_bar_item, view_switcher},
Element, Element,
ElementExt, ElementExt,
}; };
@ -145,61 +145,61 @@ impl Application for Window {
let content = responsive(|size| { let content = responsive(|size| {
let condensed = size.width < 900.0; let condensed = size.width < 900.0;
let sidebar: Element<_> = nav_bar() let sidebar: Element<_> = nav_bar()
.source(BTreeMap::from([ .source(BTreeMap::from([
( (
nav_bar_item()
.title("Network & Wireless")
.icon("nm-device-wired"),
vec![nav_bar_item().title("Wi-Fi").icon("network-wireless")],
),
(
nav_bar_item().title("Bluetooth").icon("cs-bluetooth"),
vec![nav_bar_item().title("Devices").icon("computer")],
),
(
nav_bar_item()
.title("Personalization")
.icon("applications-system"),
vec![
nav_bar_item() nav_bar_item()
.title("Network & Wireless") .title("Desktop Session")
.icon("nm-device-wired"), .icon("desktop-panel"),
vec![nav_bar_item().title("Wi-Fi").icon("network-wireless")],
),
(
nav_bar_item().title("Bluetooth").icon("cs-bluetooth"),
vec![nav_bar_item().title("Devices").icon("computer")],
),
(
nav_bar_item() nav_bar_item()
.title("Personalization") .title("Wallpaper")
.icon("applications-system"), .icon("preferences-desktop-wallpaper"),
vec![ nav_bar_item().title("Appearance").icon("cs-color"),
nav_bar_item() nav_bar_item()
.title("Desktop Session") .title("Dock & Top Panel")
.icon("desktop-panel"), .icon("desktop-panel"),
nav_bar_item() nav_bar_item()
.title("Wallpaper") .title("Workspaces")
.icon("preferences-desktop-wallpaper"), .icon("preferences-system-windows"),
nav_bar_item().title("Appearance").icon("cs-color"), nav_bar_item()
nav_bar_item() .title("Notifications")
.title("Dock & Top Panel") .icon("cs-notifications"),
.icon("desktop-panel"), ],
nav_bar_item() ),
.title("Workspaces") (
.icon("preferences-system-windows"), nav_bar_item().title("Input Devices").icon("input-keyboard"),
nav_bar_item() vec![nav_bar_item().title("Keyboard").icon("computer")],
.title("Notifications") ),
.icon("cs-notifications"), (
], nav_bar_item().title("Displays").icon("cs-display"),
), vec![nav_bar_item().title("External Monitors").icon("computer")],
( ),
nav_bar_item().title("Input Devices").icon("input-keyboard"), (
vec![nav_bar_item().title("Keyboard").icon("computer")], nav_bar_item().title("Power & Battery").icon("battery"),
), vec![nav_bar_item().title("Status").icon("computer")],
( ),
nav_bar_item().title("Displays").icon("cs-display"), (
vec![nav_bar_item().title("External Monitors").icon("computer")], nav_bar_item().title("Sound").icon("sound"),
), vec![nav_bar_item().title("Volume").icon("computer")],
( ),
nav_bar_item().title("Power & Battery").icon("battery"), ]))
vec![nav_bar_item().title("Status").icon("computer")], .on_page_selected(Box::new(Message::Page))
), .active(self.sidebar_toggled)
( .condensed(condensed)
nav_bar_item().title("Sound").icon("sound"), .into();
vec![nav_bar_item().title("Volume").icon("computer")],
),
]))
.on_page_selected(Box::new(Message::Page))
.active(self.sidebar_toggled)
.condensed(condensed)
.into();
let choose_theme = [Theme::Light, Theme::Dark].iter().fold( let choose_theme = [Theme::Light, Theme::Dark].iter().fold(
row![].spacing(10).align_items(Alignment::Center), row![].spacing(10).align_items(Alignment::Center),
@ -274,6 +274,11 @@ impl Application for Window {
.width(Length::Units(250)) .width(Length::Units(250))
.height(Length::Units(4)) .height(Length::Units(4))
)) ))
.into(),
settings::view_section("View Switcher")
.add(view_switcher()
.options(vec!["Details", "Identity", "IPv4", "IPv6", "Security"])
.on_view_changed(Box::new(Message::ViewChanged)))
.into() .into()
]) ])
.into(); .into();

View file

@ -29,3 +29,6 @@ pub use scrollable::*;
pub mod separator; pub mod separator;
pub use separator::{horizontal_rule, vertical_rule}; pub use separator::{horizontal_rule, vertical_rule};
pub mod view_switcher;
pub use view_switcher::*;

View file

@ -20,9 +20,9 @@ pub mod nav_bar {
.align_items($crate::iced::alignment::Alignment::Center), .align_items($crate::iced::alignment::Alignment::Center),
) )
.style(if $active { .style(if $active {
$crate::iced::theme::Button::Primary.into() $crate::theme::Button::Primary
} else { } else {
$crate::iced::theme::Button::Text.into() $crate::theme::Button::Text
}) })
} else { } else {
$crate::iced::widget::Button::new( $crate::iced::widget::Button::new(
@ -34,9 +34,9 @@ pub mod nav_bar {
) )
.padding(10) .padding(10)
.style(if $active { .style(if $active {
$crate::iced::theme::Button::Primary.into() $crate::theme::Button::Primary
} else { } else {
$crate::iced::theme::Button::Text.into() $crate::theme::Button::Text
}) })
} }
}; };

View file

@ -1,16 +1,17 @@
// Copyright 2022 System76 <info@system76.com> // Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::Renderer;
use crate::widget::nav_bar::{nav_bar_pages_style, nav_bar_sections_style}; use crate::widget::nav_bar::{nav_bar_pages_style, nav_bar_sections_style};
use crate::widget::{icon, scrollable}; use crate::widget::{icon, scrollable};
use crate::{theme, Renderer, Theme}; use crate::iced::{Length, Background};
use derive_setters::Setters; use crate::iced_lazy::Component;
use iced::{Background, Length}; use crate::iced::widget::{button, column, container, text};
use iced_lazy::Component; use crate::iced_native::{row, Alignment, Element};
use iced_native::widget::{button, column, container, text}; use crate::iced_style::button::Appearance;
use iced_native::{row, Alignment, Element}; use crate::{theme, Theme};
use iced_style::button::Appearance;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use derive_setters::Setters;
#[derive(Setters, Default)] #[derive(Setters, Default)]
pub struct NavBar<'a, Message> { pub struct NavBar<'a, Message> {
@ -93,71 +94,111 @@ impl<'a, Message> Component<Message, Renderer> for NavBar<'a, Message> {
fn view(&self, state: &Self::State) -> Element<Self::Event, Renderer> { fn view(&self, state: &Self::State) -> Element<Self::Event, Renderer> {
if self.active { if self.active {
let mut sections: Vec<Element<'a, Self::Event, Renderer>> = vec![]; let mut sections: Vec<Element<Self::Event, Renderer>> = vec![];
let mut pages: Vec<Element<'a, Self::Event, Renderer>> = vec![]; let mut pages: Vec<Element<Self::Event, Renderer>> = vec![];
for (section_index, (section, section_pages)) in self.source.iter().enumerate() { for (section_index, (section, section_pages)) in self.source.iter().enumerate() {
sections.push( sections.push(
crate::nav_button!( button(
&section.title, column(vec![
&section.icon, icon(&section.icon, 20).into(),
true, text(&section.title).size(14).into(),
section_index == state.selected_section ])
.width(Length::Units(100))
.height(Length::Units(50))
.align_items(Alignment::Center),
) )
.style(if section_index == state.selected_section {
theme::Button::Primary.into()
} else {
theme::Button::Text.into()
})
.on_press(NavBarEvent::SectionSelected(section_index)) .on_press(NavBarEvent::SectionSelected(section_index))
.into(), .into(),
); );
if section_index == state.selected_section { if section_index == state.selected_section {
for (page_index, page) in section_pages.iter().enumerate() { for (page_index, page) in section_pages.iter().enumerate() {
let active = state.selected_page.is_some() pages.push(if self.condensed {
&& page_index == state.selected_page.unwrap(); button(
pages.push( column(vec![
crate::nav_button!(&page.title, &page.icon, self.condensed, active) icon(&page.icon, 20).into(),
.on_press(NavBarEvent::PageSelected(section_index, page_index)) text(&page.title).size(14).into(),
.into(), ])
); .width(Length::Units(100))
.height(Length::Units(50))
.align_items(Alignment::Center),
)
.style(if let Some(selected_page) = state.selected_page {
if page_index == selected_page {
theme::Button::Primary.into()
} else {
theme::Button::Text.into()
}
} else {
theme::Button::Text.into()
}).on_press(NavBarEvent::PageSelected(section_index, page_index))
.into()
} else {
button(row![
icon(&page.icon, 20),
text(&page.title).size(16).width(Length::Fill)
].spacing(10))
.padding(10)
.style(if let Some(selected_page) = state.selected_page {
if page_index == selected_page {
theme::Button::Primary.into()
} else {
theme::Button::Text.into()
}
} else {
theme::Button::Text.into()
})
.on_press(NavBarEvent::PageSelected(section_index, page_index))
.into()
});
} }
} }
} }
let nav_bar: Element<Self::Event, Renderer> = let nav_bar: Element<Self::Event, Renderer> = container(if self.condensed {
container(if self.condensed && state.selected_page.is_some() { row![
row![container(scrollable(column(pages) scrollable(column(sections)
.spacing(10)
.padding(10)
.max_width(200)
.width(Length::Units(200))
.height(Length::Shrink)))
.height(Length::Fill)
.style(theme::Container::Custom(nav_bar_pages_style))]
} else if !state.section_active || self.condensed && state.selected_page.is_none() {
row![scrollable(column(sections)
.spacing(10) .spacing(10)
.padding(10) .padding(10)
.max_width(100) .max_width(100)
.align_items(Alignment::Center) .align_items(Alignment::Center)
.height(Length::Shrink))] .height(Length::Shrink)),
} else { container(scrollable(column(pages)
row![ .spacing(10)
scrollable(column(sections) .padding(10)
.spacing(10) .max_width(100)
.padding(10) .align_items(Alignment::Center)
.max_width(100) .width(Length::Units(100))
.align_items(Alignment::Center) .height(Length::Shrink)))
.height(Length::Shrink)), .height(Length::Fill)
container(scrollable(column(pages) .style(theme::Container::Custom(nav_bar_pages_style)),
.spacing(10) ]
.padding(10) } else {
.max_width(200) row![
.width(Length::Units(200)) scrollable(column(sections)
.height(Length::Shrink))) .spacing(10)
.height(Length::Fill) .padding(10)
.style(theme::Container::Custom(nav_bar_pages_style)), .max_width(100)
] .align_items(Alignment::Center)
}) .height(Length::Shrink)),
.height(Length::Fill) container(scrollable(column(pages)
.style(theme::Container::Custom(nav_bar_sections_style)) .spacing(10)
.into(); .padding(10)
.max_width(200)
.width(Length::Units(200))
.height(Length::Shrink)))
.height(Length::Fill)
.style(theme::Container::Custom(nav_bar_pages_style)),
]
})
.height(Length::Fill)
.style(theme::Container::Custom(nav_bar_sections_style))
.into();
nav_bar nav_bar
} else { } else {
row![].into() row![].into()
@ -183,4 +224,4 @@ pub fn section_button_style(theme: &Theme) -> Appearance {
border_color: Default::default(), border_color: Default::default(),
text_color: Default::default(), text_color: Default::default(),
} }
} }

View file

@ -1,10 +1,10 @@
use derive_setters::Setters; use derive_setters::Setters;
use iced::{ use iced::{
alignment::{Horizontal, Vertical}, alignment::{Horizontal, Vertical},
theme,
widget::{button, container, text, Row}, widget::{button, container, text, Row},
Background, Element, Length, Renderer, Theme, Alignment, Background, Length, Alignment,
}; };
use crate::{Element, Renderer, Theme, theme};
use iced_lazy::Component; use iced_lazy::Component;
#[derive(Setters)] #[derive(Setters)]
@ -40,8 +40,8 @@ impl<'a, Message> Component<Message, Renderer> for ViewSwitcher<'a, Message> {
self.on_view_changed.as_ref().map(|on_view_changed| (on_view_changed)(state.selected_view)) self.on_view_changed.as_ref().map(|on_view_changed| (on_view_changed)(state.selected_view))
} }
fn view(&self, state: &Self::State) -> Element<'_, Self::Event, Renderer> { fn view(&self, state: &Self::State) -> Element<Self::Event> {
let mut options: Vec<Element<'a, Self::Event, Renderer>> = vec![]; let mut options: Vec<Element<Self::Event>> = vec![];
for (index, option) in self.options.iter().enumerate() { for (index, option) in self.options.iter().enumerate() {
options.push( options.push(