diff options
author | 2023-03-14 15:46:04 -0600 | |
---|---|---|
committer | 2023-03-14 15:46:04 -0600 | |
commit | addc443f8ddb688248cc1d34e55ee7beed42195c (patch) | |
tree | 88d69f6c23211e67d1cc1115e1735bb41dc91b50 /examples/radio | |
parent | c96ab27b24a5775aeef7d8a0ed31214a5cb3f0a7 (diff) | |
download | iced-addc443f8ddb688248cc1d34e55ee7beed42195c.tar.gz iced-addc443f8ddb688248cc1d34e55ee7beed42195c.tar.bz2 iced-addc443f8ddb688248cc1d34e55ee7beed42195c.zip |
Working more on example
Diffstat (limited to 'examples/radio')
-rw-r--r-- | examples/radio/src/main.rs | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/examples/radio/src/main.rs b/examples/radio/src/main.rs index 424fdf42..8881f059 100644 --- a/examples/radio/src/main.rs +++ b/examples/radio/src/main.rs @@ -7,14 +7,12 @@ pub fn main() -> iced::Result { #[derive(Default)] struct Example { - default_checkbox: bool, - custom_checkbox: bool, + selected_radio: Option<Choice>, } #[derive(Debug, Clone, Copy)] enum Message { - DefaultChecked(bool), - CustomChecked(bool), + RadioSelected(Choice), } impl Sandbox for Example { @@ -30,18 +28,19 @@ impl Sandbox for Example { fn update(&mut self, message: Message) { match message { - Message::DefaultChecked(value) => self.default_checkbox = value, - Message::CustomChecked(value) => self.custom_checkbox = value, + Message::RadioSelected(value) => { + self.selected_radio = Some(choice); + } } } fn view(&self) -> Element<Message> { - let selected_choice = Some(Choice::A); + let selected_radio = Some(Choice::A); - Radio::new(Choice::A, "This is A", selected_choice, Message::RadioSelected); - Radio::new(Choice::B, "This is B", selected_choice, Message::RadioSelected); + Radio::new(Choice::A, "This is A", selected_radio, Message::RadioSelected); + Radio::new(Choice::B, "This is B", selected_radio, Message::RadioSelected); - let content = column![selected_choice].spacing(22); + let content = column![selected_radio].spacing(22); container(content) .width(Length::Fill) @@ -51,3 +50,30 @@ impl Sandbox for Example { .into() } } + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum Choice { + #[default] + A, + B, +} + +impl Choice { + const ALL: [Choice; 2] = [ + Choice::A, + Choice::B, + ]; +} + +impl std::fmt::Display for Choice { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Choice::A => "A", + Choice::B => "B", + } + ) + } +} |