From 0c1396cac3f522d805b04f2e9a1dfd60cfb648fa Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Tue, 9 May 2023 16:26:26 -0400 Subject: [PATCH] feat: example improvements --- examples/cosmic-sctk/src/window.rs | 19 +++++++++++++++---- examples/cosmic/src/main.rs | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/cosmic-sctk/src/window.rs b/examples/cosmic-sctk/src/window.rs index d930c021..d07f1c55 100644 --- a/examples/cosmic-sctk/src/window.rs +++ b/examples/cosmic-sctk/src/window.rs @@ -12,7 +12,7 @@ use cosmic::{ widget::{ button, header_bar, nav_bar, nav_bar_toggle, rectangle_tracker::{rectangle_tracker_subscription, RectangleTracker, RectangleUpdate}, - scrollable, segmented_button, settings, toggler, IconSource, + scrollable, segmented_button, segmented_selection, settings, toggler, IconSource, }, Element, ElementExt, }; @@ -116,6 +116,7 @@ pub struct Window { show_maximize: bool, exit: bool, rectangle_tracker: Option>, + pub selection: segmented_button::SingleSelectModel, } impl Window { @@ -175,6 +176,7 @@ pub enum Message { Rectangle(RectangleUpdate), NavBar(segmented_button::Entity), Ignore, + Selection(segmented_button::Entity), } impl Application for Window { @@ -188,6 +190,11 @@ impl Application for Window { .nav_bar_toggled(true) .show_maximize(true) .show_minimize(true); + window.selection = segmented_button::Model::builder() + .insert(|b| b.text("Choice A").activate()) + .insert(|b| b.text("Choice B")) + .insert(|b| b.text("Choice C")) + .build(); window.slider_value = 50.0; // window.theme = Theme::Light; window.pick_list_selected = Some("Option 1"); @@ -253,6 +260,7 @@ impl Application for Window { } }, Message::Ignore => {} + Message::Selection(key) => self.selection.activate(key), } Command::none() @@ -302,7 +310,7 @@ impl Application for Window { widgets.push(nav_bar.debug(self.debug)); } - if !(self.is_condensed() && nav_bar_toggled) { + if !nav_bar_toggled { let secondary = button(ButtonTheme::Secondary) .text("Secondary") .on_press(Message::ButtonPressed); @@ -371,12 +379,15 @@ impl Application for Window { .width(Length::Fixed(250.0)) .height(Length::Fixed(4.0)), )) + .add(settings::item( + "Segmented Button", + segmented_selection::horizontal(&self.selection) + .on_activate(Message::Selection), + )) .into(), ]) .into(); - let mut widgets: Vec> = Vec::with_capacity(2); - widgets.push( scrollable(row![ horizontal_space(Length::Fill), diff --git a/examples/cosmic/src/main.rs b/examples/cosmic/src/main.rs index 143a7b65..5700a590 100644 --- a/examples/cosmic/src/main.rs +++ b/examples/cosmic/src/main.rs @@ -9,7 +9,7 @@ pub use window::*; pub fn main() -> cosmic::iced::Result { let env = Env::default() - .filter_or("MY_LOG_LEVEL", "debug") + .filter_or("MY_LOG_LEVEL", "info") .write_style_or("MY_LOG_STYLE", "always"); env_logger::init_from_env(env);