summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--examples/radio/Cargo.toml10
-rw-r--r--examples/radio/src/main.rs86
-rw-r--r--native/src/widget/helpers.rs2
-rw-r--r--native/src/widget/radio.rs37
4 files changed, 33 insertions, 102 deletions
diff --git a/examples/radio/Cargo.toml b/examples/radio/Cargo.toml
deleted file mode 100644
index a8c7f351..00000000
--- a/examples/radio/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name = "radio"
-version = "0.1.0"
-authors = ["Aaron Honeycutt <aaronhoneycutt@proton.me>"]
-edition = "2021"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-iced = { path = "../.." }
diff --git a/examples/radio/src/main.rs b/examples/radio/src/main.rs
deleted file mode 100644
index 3b19924e..00000000
--- a/examples/radio/src/main.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-use iced::widget::{column, container, radio};
-use iced::{Element, Length, Sandbox, Settings};
-
-pub fn main() -> iced::Result {
- Example::run(Settings::default())
-}
-
-#[derive(Default)]
-struct Example {
- radio: Option<Choice>,
-}
-
-#[derive(Debug, Clone, Copy)]
-enum Message {
- RadioSelected(Choice),
-}
-
-impl Sandbox for Example {
- type Message = Message;
-
- fn new() -> Self {
- Default::default()
- }
-
- fn title(&self) -> String {
- String::from("Radio - Iced")
- }
-
- fn update(&mut self, message: Message) {
- match message {
- Message::RadioSelected(value) => {
- self.radio = Some(value);
- }
- }
- }
-
- fn view(&self) -> Element<Message> {
- 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![
- a_checkbox,
- b_checkbox,
- c_checkbox,
- all_checkbox,
- ]
- .spacing(20)
- .padding(20)
- .max_width(600);
-
- container(content)
- .width(Length::Fill)
- .height(Length::Fill)
- .center_x()
- .center_y()
- .into()
- }
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-enum Choice {
- A,
- B,
- C,
- All,
-}
diff --git a/native/src/widget/helpers.rs b/native/src/widget/helpers.rs
index d13eca75..24853eaa 100644
--- a/native/src/widget/helpers.rs
+++ b/native/src/widget/helpers.rs
@@ -147,7 +147,7 @@ where
Renderer::Theme: widget::radio::StyleSheet,
V: Copy + Eq,
{
- widget::Radio::new(value, label, selected, on_click)
+ widget::Radio::new(label, value, selected, on_click)
}
/// Creates a new [`Toggler`].
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index 9daddfbc..3ca041bf 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -21,10 +21,13 @@ pub use iced_style::radio::{Appearance, StyleSheet};
/// # type Radio<Message> =
/// # iced_native::widget::Radio<Message, iced_native::renderer::Null>;
/// #
+/// # use iced_native::column;
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// pub enum Choice {
/// A,
/// B,
+/// C,
+/// All,
/// }
///
/// #[derive(Debug, Clone, Copy)]
@@ -34,12 +37,36 @@ pub use iced_style::radio::{Appearance, StyleSheet};
///
/// let selected_choice = Some(Choice::A);
///
-/// Radio::new(Choice::A, "This is A", selected_choice, Message::RadioSelected);
+/// let a = Radio::new(
+/// "A",
+/// Choice::A,
+/// selected_choice,
+/// Message::RadioSelected,
+/// );
///
-/// Radio::new(Choice::B, "This is B", selected_choice, Message::RadioSelected);
-/// ```
+/// let b = Radio::new(
+/// "B",
+/// Choice::B,
+/// selected_choice,
+/// Message::RadioSelected,
+/// );
+///
+/// let c = Radio::new(
+/// "C",
+/// Choice::C,
+/// selected_choice,
+/// Message::RadioSelected,
+/// );
+///
+/// let all = Radio::new(
+/// "All of the above",
+/// Choice::All,
+/// selected_choice,
+/// Message::RadioSelected
+/// );
///
-/// ![Radio buttons drawn by `iced_wgpu`](https://github.com/iced-rs/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/radio.png?raw=true)
+/// let content = column![a, b, c, all];
+/// ```
#[allow(missing_debug_implementations)]
pub struct Radio<Message, Renderer>
where
@@ -78,8 +105,8 @@ where
/// * a function that will be called when the [`Radio`] is selected. It
/// receives the value of the radio and must produce a `Message`.
pub fn new<F, V>(
- value: V,
label: impl Into<String>,
+ value: V,
selected: Option<V>,
f: F,
) -> Self