diff options
| author | 2023-10-02 20:18:15 +0200 | |
|---|---|---|
| committer | 2024-02-01 13:16:28 +0100 | |
| commit | b5f1ca169567f47b3976de5b4c5a2b1ce37656d5 (patch) | |
| tree | 326fae951f16d98ba6141e6cd20d6e7d02e8c71d /examples | |
| parent | b95f3ab12f863f4de668e4e6f8a75b7d3acdf2b7 (diff) | |
| download | iced-b5f1ca169567f47b3976de5b4c5a2b1ce37656d5.tar.gz iced-b5f1ca169567f47b3976de5b4c5a2b1ce37656d5.tar.bz2 iced-b5f1ca169567f47b3976de5b4c5a2b1ce37656d5.zip | |
Introduce support for disabling a `checkbox`
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/checkbox/src/main.rs | 59 | ||||
| -rw-r--r-- | examples/custom_shader/src/main.rs | 7 | ||||
| -rw-r--r-- | examples/events/src/main.rs | 7 | ||||
| -rw-r--r-- | examples/game_of_life/src/main.rs | 3 | ||||
| -rw-r--r-- | examples/layout/src/main.rs | 3 | ||||
| -rw-r--r-- | examples/styling/src/main.rs | 7 | ||||
| -rw-r--r-- | examples/svg/src/main.rs | 8 | ||||
| -rw-r--r-- | examples/todos/src/main.rs | 11 | ||||
| -rw-r--r-- | examples/tour/src/main.rs | 33 | ||||
| -rw-r--r-- | examples/vectorial_text/src/main.rs | 7 |
10 files changed, 81 insertions, 64 deletions
diff --git a/examples/checkbox/src/main.rs b/examples/checkbox/src/main.rs index ef1a054d..314cb3fe 100644 --- a/examples/checkbox/src/main.rs +++ b/examples/checkbox/src/main.rs @@ -1,6 +1,7 @@ use iced::executor; use iced::font::{self, Font}; -use iced::widget::{checkbox, column, container, text}; +use iced::theme::Checkbox; +use iced::widget::{checkbox, column, container, row, text}; use iced::{Application, Command, Element, Length, Settings, Theme}; const ICON_FONT: Font = Font::with_name("icons"); @@ -13,12 +14,15 @@ pub fn main() -> iced::Result { struct Example { default_checkbox: bool, custom_checkbox: bool, + styled_checkbox_enabled: bool, + styled_checkbox_checked: bool, } #[derive(Debug, Clone, Copy)] enum Message { DefaultChecked(bool), CustomChecked(bool), + StyledChecked(bool), FontLoaded(Result<(), font::Error>), } @@ -42,8 +46,14 @@ impl Application for Example { fn update(&mut self, message: Message) -> Command<Message> { match message { - Message::DefaultChecked(value) => self.default_checkbox = value, + Message::DefaultChecked(value) => { + self.default_checkbox = value; + self.styled_checkbox_enabled = value; + } Message::CustomChecked(value) => self.custom_checkbox = value, + Message::StyledChecked(value) => { + self.styled_checkbox_checked = value + } Message::FontLoaded(_) => (), } @@ -51,19 +61,40 @@ impl Application for Example { } fn view(&self) -> Element<Message> { - let default_checkbox = - checkbox("Default", self.default_checkbox, Message::DefaultChecked); - let custom_checkbox = - checkbox("Custom", self.custom_checkbox, Message::CustomChecked) - .icon(checkbox::Icon { - font: ICON_FONT, - code_point: '\u{e901}', - size: None, - line_height: text::LineHeight::Relative(1.0), - shaping: text::Shaping::Basic, - }); + let default_checkbox = checkbox("Default", self.default_checkbox) + .on_toggle(Message::DefaultChecked); - let content = column![default_checkbox, custom_checkbox].spacing(22); + let checkboxes = [ + ("Primary", Checkbox::Primary), + ("Secondary", Checkbox::Secondary), + ("Success", Checkbox::Success), + ("Danger", Checkbox::Danger), + ]; + + let checkboxes = row(checkboxes + .into_iter() + .map(|(label, style)| { + checkbox(label, self.styled_checkbox_checked) + .on_toggle_maybe( + self.default_checkbox.then(|| Message::StyledChecked), + ) + .style(style) + }) + .map(Element::from)) + .spacing(10); + + let custom_checkbox = checkbox("Custom", self.custom_checkbox) + .on_toggle(Message::CustomChecked) + .icon(checkbox::Icon { + font: ICON_FONT, + code_point: '\u{e901}', + size: None, + line_height: text::LineHeight::Relative(1.0), + shaping: text::Shaping::Basic, + }); + + let content = + column![default_checkbox, checkboxes, custom_checkbox,].spacing(22); container(content) .width(Length::Fill) diff --git a/examples/custom_shader/src/main.rs b/examples/custom_shader/src/main.rs index 78b2fbbb..9e8da3ba 100644 --- a/examples/custom_shader/src/main.rs +++ b/examples/custom_shader/src/main.rs @@ -89,11 +89,8 @@ impl Application for IcedCubes { .step(0.01) .width(100), ), - checkbox( - "Show Depth Buffer", - self.scene.show_depth_buffer, - Message::ShowDepthBuffer - ), + checkbox("Show Depth Buffer", self.scene.show_depth_buffer) + .on_toggle(Message::ShowDepthBuffer), ] .spacing(40); diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs index fc51ac4a..d5d496c7 100644 --- a/examples/events/src/main.rs +++ b/examples/events/src/main.rs @@ -85,11 +85,8 @@ impl Application for Events { .map(Element::from), ); - let toggle = checkbox( - "Listen to runtime events", - self.enabled, - Message::Toggled, - ); + let toggle = checkbox("Listen to runtime events", self.enabled) + .on_toggle(Message::Toggled); let exit = button( text("Exit") diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 56f7afd5..b386b0cd 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -185,7 +185,8 @@ fn view_controls<'a>( row