Add desktop options page

This commit is contained in:
Jeremy Soller 2022-12-20 16:02:44 -07:00
parent aa7b66c925
commit 98815f5131
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
3 changed files with 159 additions and 69 deletions

View file

@ -17,14 +17,23 @@ use cosmic::{
use std::vec; use std::vec;
use theme::Button as ButtonTheme; use theme::Button as ButtonTheme;
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum DesktopPage {
Root,
DesktopOptions,
Wallpaper,
Appearance,
DockAndTopPanel,
Workspaces,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Page { pub enum Page {
Demo, Demo,
WiFi, WiFi,
Networking, Networking,
Bluetooth, Bluetooth,
#[default] //TODO: what should the default page be? Desktop(DesktopPage),
Desktop,
InputDevices, InputDevices,
Displays, Displays,
PowerAndBattery, PowerAndBattery,
@ -38,6 +47,13 @@ pub enum Page {
Applications, Applications,
} }
impl Default for Page {
fn default() -> Page {
//TODO: what should the default page be?
Page::Desktop(DesktopPage::Root)
}
}
#[derive(Default)] #[derive(Default)]
pub struct Window { pub struct Window {
title: String, title: String,
@ -180,79 +196,129 @@ impl Window {
.into() .into()
} }
fn view_desktop(&self) -> Element<Message> { fn view_desktop_root(&self) -> Element<Message> {
settings::view_column(vec![ settings::view_column(vec![
text("Desktop").size(32).into(), text("Desktop").size(32).into(),
//TODO: simplify these buttons! //TODO: simplify these buttons!
container(settings::item_row(vec![ iced::widget::Button::new(
icon("video-display-symbolic", 16).style(theme::Svg::Symbolic).into(), container(settings::item_row(vec![
column!( icon("video-display-symbolic", 16).style(theme::Svg::Symbolic).into(),
text("Desktop Options").size(16), column!(
text("Super Key action, hot corners, window control options.").size(12), text("Desktop Options").size(16),
).into(), text("Super Key action, hot corners, window control options.").size(12),
horizontal_space(iced::Length::Fill).into(), ).into(),
icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(), horizontal_space(iced::Length::Fill).into(),
]).spacing(16)) icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(),
.padding([20, 32]) ]).spacing(16))
.style(theme::Container::Custom(list::column::style)) .padding([20, 32])
.style(theme::Container::Custom(list::column::style))
)
.style(theme::Button::Transparent)
.on_press(Message::Page(Page::Desktop(DesktopPage::DesktopOptions)))
.into(), .into(),
container(settings::item_row(vec![ iced::widget::Button::new(
icon("preferences-desktop-wallpaper-symbolic", 16).style(theme::Svg::Symbolic).into(), container(settings::item_row(vec![
column!( icon("preferences-desktop-wallpaper-symbolic", 16).style(theme::Svg::Symbolic).into(),
text("Wallpaper").size(16), column!(
text("Background images, colors, and slideshow options.").size(12), text("Wallpaper").size(16),
).into(), text("Background images, colors, and slideshow options.").size(12),
horizontal_space(iced::Length::Fill).into(), ).into(),
icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(), horizontal_space(iced::Length::Fill).into(),
]).spacing(16)) icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(),
.padding([20, 32]) ]).spacing(16))
.style(theme::Container::Custom(list::column::style)) .padding([20, 32])
.style(theme::Container::Custom(list::column::style))
)
.style(theme::Button::Transparent)
.on_press(Message::Page(Page::Desktop(DesktopPage::Wallpaper)))
.into(), .into(),
container(settings::item_row(vec![ iced::widget::Button::new(
icon("preferences-pop-desktop-appearance-symbolic", 16).style(theme::Svg::Symbolic).into(), container(settings::item_row(vec![
column!( icon("preferences-pop-desktop-appearance-symbolic", 16).style(theme::Svg::Symbolic).into(),
text("Appearance").size(16), column!(
text("Accent colors and COSMIC theming").size(12), text("Appearance").size(16),
).into(), text("Accent colors and COSMIC theming").size(12),
horizontal_space(iced::Length::Fill).into(), ).into(),
icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(), horizontal_space(iced::Length::Fill).into(),
]).spacing(16)) icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(),
.padding([20, 32]) ]).spacing(16))
.style(theme::Container::Custom(list::column::style)) .padding([20, 32])
.style(theme::Container::Custom(list::column::style))
)
.style(theme::Button::Transparent)
.on_press(Message::Page(Page::Desktop(DesktopPage::Appearance)))
.into(), .into(),
container(settings::item_row(vec![ iced::widget::Button::new(
icon("preferences-pop-desktop-dock-symbolic", 16).style(theme::Svg::Symbolic).into(), container(settings::item_row(vec![
column!( icon("preferences-pop-desktop-dock-symbolic", 16).style(theme::Svg::Symbolic).into(),
text("Dock & Top Panel").size(16), column!(
text("Customize size, positions, and more for Dock and Top Panel.").size(12), text("Dock & Top Panel").size(16),
).into(), text("Customize size, positions, and more for Dock and Top Panel.").size(12),
horizontal_space(iced::Length::Fill).into(), ).into(),
icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(), horizontal_space(iced::Length::Fill).into(),
]).spacing(16)) icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(),
.padding([20, 32]) ]).spacing(16))
.style(theme::Container::Custom(list::column::style)) .padding([20, 32])
.style(theme::Container::Custom(list::column::style))
)
.style(theme::Button::Transparent)
.on_press(Message::Page(Page::Desktop(DesktopPage::DockAndTopPanel)))
.into(), .into(),
container(settings::item_row(vec![ iced::widget::Button::new(
icon("preferences-pop-desktop-workspaces-symbolic", 16).style(theme::Svg::Symbolic).into(), container(settings::item_row(vec![
column!( icon("preferences-pop-desktop-workspaces-symbolic", 16).style(theme::Svg::Symbolic).into(),
text("Workspaces").size(16), column!(
text("Set workspace number, behavior, and placement.").size(12), text("Workspaces").size(16),
).into(), text("Set workspace number, behavior, and placement.").size(12),
horizontal_space(iced::Length::Fill).into(), ).into(),
icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(), horizontal_space(iced::Length::Fill).into(),
]).spacing(16)) icon("go-next-symbolic", 16).style(theme::Svg::Symbolic).into(),
.padding([20, 32]) ]).spacing(16))
.style(theme::Container::Custom(list::column::style)) .padding([20, 32])
.style(theme::Container::Custom(list::column::style))
)
.style(theme::Button::Transparent)
.on_press(Message::Page(Page::Desktop(DesktopPage::Workspaces)))
.into(), .into(),
]) ])
.into() .into()
} }
fn view_desktop_options(&self) -> Element<Message> {
settings::view_column(vec![
column!(
iced::widget::Button::new(row!(
icon("go-previous-symbolic", 16).style(theme::Svg::SymbolicLink),
text("Desktop").size(16),
))
.padding(0)
.style(theme::Button::Link)
.on_press(Message::Page(Page::Desktop(DesktopPage::Root))),
text("Desktop Options").size(32),
)
.spacing(10)
.into(),
settings::view_section("Super Key Action")
.add(settings::item("TODO", toggler(None, self.toggler_value, Message::TogglerToggled)))
.into(),
settings::view_section("Hot Corner")
.add(settings::item("Enable top-left hot corner for Workspaces", toggler(None, self.toggler_value, Message::TogglerToggled)))
.into(),
settings::view_section("Top Panel")
.add(settings::item("Show Workspaces Button", toggler(None, self.toggler_value, Message::TogglerToggled)))
.add(settings::item("Show Applications Button", toggler(None, self.toggler_value, Message::TogglerToggled)))
.into(),
]).into()
}
} }
impl Application for Window { impl Application for Window {
@ -342,8 +408,8 @@ impl Application for Window {
.on_press(Message::Page(Page::Networking)), .on_press(Message::Page(Page::Networking)),
cosmic::nav_button!("bluetooth-active-symbolic", "Bluetooth", condensed, self.page == Page::Bluetooth) cosmic::nav_button!("bluetooth-active-symbolic", "Bluetooth", condensed, self.page == Page::Bluetooth)
.on_press(Message::Page(Page::Bluetooth)), .on_press(Message::Page(Page::Bluetooth)),
cosmic::nav_button!("video-display-symbolic", "Desktop", condensed, self.page == Page::Desktop) cosmic::nav_button!("video-display-symbolic", "Desktop", condensed, matches!(self.page, Page::Desktop(_)))
.on_press(Message::Page(Page::Desktop)), .on_press(Message::Page(Page::Desktop(DesktopPage::Root))),
cosmic::nav_button!("input-keyboard-symbolic", "Input Devices", condensed, self.page == Page::InputDevices) cosmic::nav_button!("input-keyboard-symbolic", "Input Devices", condensed, self.page == Page::InputDevices)
.on_press(Message::Page(Page::InputDevices)), .on_press(Message::Page(Page::InputDevices)),
cosmic::nav_button!("preferences-desktop-display-symbolic", "Displays", condensed, self.page == Page::Displays) cosmic::nav_button!("preferences-desktop-display-symbolic", "Displays", condensed, self.page == Page::Displays)
@ -375,7 +441,8 @@ impl Application for Window {
let content: Element<_> = match self.page { let content: Element<_> = match self.page {
Page::Demo => self.view_demo(), Page::Demo => self.view_demo(),
Page::Desktop => self.view_desktop(), Page::Desktop(DesktopPage::Root) => self.view_desktop_root(),
Page::Desktop(DesktopPage::DesktopOptions) => self.view_desktop_options(),
_ => settings::view_column(vec![ _ => settings::view_column(vec![
text("Unimplemented page").into() text("Unimplemented page").into()
]).into(), ]).into(),

View file

@ -128,6 +128,8 @@ pub enum Button {
Primary, Primary,
Secondary, Secondary,
Text, Text,
Link,
LinkActive,
Transparent, Transparent,
Custom { Custom {
active: fn(&Theme) -> button::Appearance, active: fn(&Theme) -> button::Appearance,
@ -150,6 +152,8 @@ impl Button {
Button::Positive => &cosmic.success, Button::Positive => &cosmic.success,
Button::Destructive => &cosmic.destructive, Button::Destructive => &cosmic.destructive,
Button::Text => &cosmic.secondary.component, Button::Text => &cosmic.secondary.component,
Button::Link => &cosmic.accent,
Button::LinkActive => &cosmic.secondary.component,
Button::Transparent => &TRANSPARENT_COMPONENT, Button::Transparent => &TRANSPARENT_COMPONENT,
Button::Deactivated => &cosmic.secondary.component, Button::Deactivated => &cosmic.secondary.component,
Button::Custom { .. } => &TRANSPARENT_COMPONENT Button::Custom { .. } => &TRANSPARENT_COMPONENT
@ -168,12 +172,21 @@ impl button::StyleSheet for Theme {
let cosmic = style.cosmic(self); let cosmic = style.cosmic(self);
button::Appearance { button::Appearance {
border_radius: 24.0, border_radius: match style {
Button::Link => 0.0,
_ => 24.0,
},
background: match style { background: match style {
Button::Text => None, Button::Text => None,
Button::Link => None,
Button::LinkActive => Some(Background::Color(cosmic.divider.into())),
_ => Some(Background::Color(cosmic.base.into())), _ => Some(Background::Color(cosmic.base.into())),
}, },
text_color: cosmic.on.into(), text_color: match style {
Button::Link => cosmic.base.into(),
Button::LinkActive => cosmic.selected_text.into(),
_ => cosmic.on.into(),
},
..button::Appearance::default() ..button::Appearance::default()
} }
} }
@ -187,7 +200,11 @@ impl button::StyleSheet for Theme {
let cosmic = style.cosmic(self); let cosmic = style.cosmic(self);
button::Appearance { button::Appearance {
background: Some(Background::Color(cosmic.hover.into())), background: match style {
Button::Link => None,
Button::LinkActive => Some(Background::Color(cosmic.divider.into())),
_ => Some(Background::Color(cosmic.hover.into()))
},
..active ..active
} }
} }
@ -712,6 +729,8 @@ pub enum Svg {
SymbolicActive, SymbolicActive,
/// Icon fill color will match on primary color /// Icon fill color will match on primary color
SymbolicPrimary, SymbolicPrimary,
/// Icon fill color will use accent color
SymbolicLink,
} }
impl Hash for Svg { impl Hash for Svg {
@ -722,6 +741,7 @@ impl Hash for Svg {
Svg::Symbolic => 2, Svg::Symbolic => 2,
Svg::SymbolicActive => 3, Svg::SymbolicActive => 3,
Svg::SymbolicPrimary => 4, Svg::SymbolicPrimary => 4,
Svg::SymbolicLink => 5,
}; };
id.hash(state); id.hash(state);
@ -744,6 +764,9 @@ impl svg::StyleSheet for Theme {
Svg::SymbolicPrimary => svg::Appearance { Svg::SymbolicPrimary => svg::Appearance {
color: Some(self.cosmic().accent.on.into()), color: Some(self.cosmic().accent.on.into()),
}, },
Svg::SymbolicLink => svg::Appearance {
color: Some(self.cosmic().accent.base.into()),
},
} }
} }
} }

View file

@ -12,14 +12,14 @@ pub mod nav_bar {
$crate::iced::widget::Button::new( $crate::iced::widget::Button::new(
$crate::widget::icon($icon, 22) $crate::widget::icon($icon, 22)
.style(if $active { .style(if $active {
$crate::theme::Svg::SymbolicPrimary $crate::theme::Svg::SymbolicLink
} else { } else {
$crate::theme::Svg::Symbolic $crate::theme::Svg::Symbolic
}) })
) )
.padding(8) .padding(8)
.style(if $active { .style(if $active {
$crate::theme::Button::Primary $crate::theme::Button::LinkActive
} else { } else {
$crate::theme::Button::Text $crate::theme::Button::Text
}) })
@ -28,7 +28,7 @@ pub mod nav_bar {
$crate::iced::widget::row!( $crate::iced::widget::row!(
$crate::widget::icon($icon, 16) $crate::widget::icon($icon, 16)
.style(if $active { .style(if $active {
$crate::theme::Svg::SymbolicPrimary $crate::theme::Svg::SymbolicLink
} else { } else {
$crate::theme::Svg::Symbolic $crate::theme::Svg::Symbolic
}), }),
@ -40,7 +40,7 @@ pub mod nav_bar {
.spacing(8) .spacing(8)
) )
.style(if $active { .style(if $active {
$crate::theme::Button::Primary $crate::theme::Button::LinkActive
} else { } else {
$crate::theme::Button::Text $crate::theme::Button::Text
}) })