summaryrefslogtreecommitdiffstats
path: root/examples/radio
diff options
context:
space:
mode:
authorLibravatar Aaron Honeycutt <aaronhoneycutt@protonmail.com>2023-03-17 13:32:11 -0600
committerLibravatar Aaron Honeycutt <aaronhoneycutt@protonmail.com>2023-03-17 13:32:11 -0600
commit4fdd76c07c15f85a518c240aca0e55f482b18bc3 (patch)
treee2ff20d4f08b1ecabb26af84b22e199780d351a4 /examples/radio
parentd5f26c3d39079e5a1d8aa4a18b9fb04e8834022f (diff)
downloadiced-4fdd76c07c15f85a518c240aca0e55f482b18bc3.tar.gz
iced-4fdd76c07c15f85a518c240aca0e55f482b18bc3.tar.bz2
iced-4fdd76c07c15f85a518c240aca0e55f482b18bc3.zip
Now is a working example
Diffstat (limited to 'examples/radio')
-rw-r--r--examples/radio/src/main.rs65
1 files changed, 36 insertions, 29 deletions
diff --git a/examples/radio/src/main.rs b/examples/radio/src/main.rs
index 73b03610..3b19924e 100644
--- a/examples/radio/src/main.rs
+++ b/examples/radio/src/main.rs
@@ -7,7 +7,7 @@ pub fn main() -> iced::Result {
#[derive(Default)]
struct Example {
- selected_radio: Option<Choice>,
+ radio: Option<Choice>,
}
#[derive(Debug, Clone, Copy)]
@@ -29,18 +29,44 @@ impl Sandbox for Example {
fn update(&mut self, message: Message) {
match message {
Message::RadioSelected(value) => {
- self.selected_radio = Some(choice);
+ self.radio = Some(value);
}
}
}
fn view(&self) -> Element<Message> {
- let selected_radio = Some(Choice::A);
+ let a_checkbox = radio(
+ "A",
+ Choice::A,
+ self.radio,
+ Message::RadioSelected,
+ );
+
+ let b_checkbox = radio(
+ "B",
+ Choice::B,
+ self.radio,
+ Message::RadioSelected,
+ );
+
+ let c_checkbox = radio(
+ "C",
+ Choice::C,
+ self.radio,
+ Message::RadioSelected,
+ );
+
+ let all_checkbox = radio("All of the above", Choice::All, self.radio, Message::RadioSelected);
let content = column![
- Radio::new(Choice::A, "This is A", selected_radio, Message::RadioSelected),
- Radio::new(Choice::B, "This is B", selected_radio, Message::RadioSelected),
- ];
+ a_checkbox,
+ b_checkbox,
+ c_checkbox,
+ all_checkbox,
+ ]
+ .spacing(20)
+ .padding(20)
+ .max_width(600);
container(content)
.width(Length::Fill)
@@ -51,29 +77,10 @@ impl Sandbox for Example {
}
}
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
-pub enum Choice {
- #[default]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum Choice {
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",
- }
- )
- }
+ C,
+ All,
}