feat(settings): global setting for icon theme

This commit is contained in:
Michael Aaron Murphy 2023-01-05 14:16:27 +01:00 committed by Michael Murphy
parent 043485c68d
commit 7d018a2139
8 changed files with 103 additions and 48 deletions

View file

@ -7,6 +7,7 @@ mod window;
pub use window::Window;
pub fn main() -> cosmic::iced::Result {
settings::set_default_icon_theme("Pop");
let mut settings = settings();
settings.initial_surface = InitialSurface::XdgWindow(Default::default());
Window::run(settings)

View file

@ -7,9 +7,8 @@ mod window;
pub use window::*;
pub fn main() -> cosmic::iced::Result {
settings::set_default_icon_theme("Pop");
let mut settings = settings();
settings.window.min_size = Some((600, 300));
// TODO: Window resize handles not functioning yet
settings.window.decorations = false;
Window::run(settings)
}

View file

@ -19,7 +19,7 @@ mod bluetooth;
mod demo;
use self::{demo::DemoView, desktop::DesktopPage};
use self::desktop::DesktopPage;
mod desktop;
use self::input_devices::InputDevicesPage;
@ -272,28 +272,8 @@ impl Application for Window {
.sidebar_toggled(true)
.show_maximize(true)
.show_minimize(true);
window.demo.slider_value = 50.0;
// window.theme = Theme::Light;
window.demo.pick_list_selected = Some("Option 1");
window.title = String::from("COSMIC Design System - Iced");
window.demo.spin_button.min = -10;
window.demo.spin_button.max = 10;
// Configures the demo view switcher.
let key = window.demo.view_switcher.insert("Controls", DemoView::TabA);
window.demo.view_switcher.activate(key);
window
.demo
.view_switcher
.insert("Segmented Button", DemoView::TabB);
window.demo.view_switcher.insert("Tab C", DemoView::TabC);
// Configures the demo selection button.
let key = window.demo.selection.insert("Choice A", ());
window.demo.selection.activate(key);
window.demo.selection.insert("Choice B", ());
window.demo.selection.insert("Choice C", ());
(window, Command::none())
}

View file

@ -30,6 +30,7 @@ pub enum Message {
ButtonPressed,
CheckboxToggled(bool),
Debug(bool),
IconTheme(segmented_button::Key),
PickListSelected(&'static str),
RowSelected(usize),
Selection(segmented_button::Key),
@ -45,9 +46,9 @@ pub enum Output {
ThemeChanged(Theme),
}
#[derive(Default)]
pub struct State {
pub checkbox_value: bool,
pub icon_theme: segmented_button::State<&'static str>,
pub pick_list_selected: Option<&'static str>,
pub selection: segmented_button::State<()>,
pub slider_value: f32,
@ -56,6 +57,41 @@ pub struct State {
pub view_switcher: segmented_button::State<DemoView>,
}
impl Default for State {
fn default() -> State {
State {
checkbox_value: false,
pick_list_selected: Some("Option 1"),
slider_value: 50.0,
spin_button: SpinButtonModel::default().min(-10).max(10),
toggler_value: false,
icon_theme: {
let mut icon_theme = segmented_button::State::default();
let key = icon_theme.insert("Pop", "Pop");
icon_theme.activate(key);
icon_theme.insert("Adwaita", "Adwaita");
icon_theme
},
selection: {
let mut selection = segmented_button::State::default();
let key = selection.insert("Choice A", ());
selection.activate(key);
selection.insert("Choice B", ());
selection.insert("Choice C", ());
selection
},
view_switcher: {
let mut view_switcher = segmented_button::State::default();
let key = view_switcher.insert("Controls", DemoView::TabA);
view_switcher.activate(key);
view_switcher.insert("Segmented Button", DemoView::TabB);
view_switcher.insert("Tab C", DemoView::TabC);
view_switcher
},
}
}
}
impl State {
pub(super) fn update(&mut self, message: Message) -> Option<Output> {
match message {
@ -70,6 +106,12 @@ impl State {
Message::ThemeChanged(theme) => return Some(Output::ThemeChanged(theme)),
Message::TogglerToggled(value) => self.toggler_value = value,
Message::ViewSwitcher(key) => self.view_switcher.activate(key),
Message::IconTheme(key) => {
self.icon_theme.activate(key);
if let Some(theme) = self.icon_theme.data(key) {
cosmic::settings::set_default_icon_theme(*theme);
}
}
}
None
@ -88,6 +130,9 @@ impl State {
},
);
let choose_icon_theme =
horizontal_segmented_selection(&self.icon_theme).on_activate(Message::IconTheme);
settings::view_column(vec![
window.page_title(Page::Demo),
horizontal_view_switcher(&self.view_switcher)
@ -98,6 +143,7 @@ impl State {
Some(DemoView::TabA) => settings::view_column(vec![
settings::view_section("Debug")
.add(settings::item("Debug theme", choose_theme))
.add(settings::item("Debug icon theme", choose_icon_theme))
.add(settings::item(
"Debug layout",
toggler(None, window.debug, Message::Debug),