summaryrefslogtreecommitdiffstats
path: root/widget/src/radio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/radio.rs')
-rw-r--r--widget/src/radio.rs136
1 files changed, 99 insertions, 37 deletions
diff --git a/widget/src/radio.rs b/widget/src/radio.rs
index cfa961f3..300318fd 100644
--- a/widget/src/radio.rs
+++ b/widget/src/radio.rs
@@ -1,4 +1,61 @@
-//! Create choices using radio buttons.
+//! Radio buttons let users choose a single option from a bunch of options.
+//!
+//! # Example
+//! ```no_run
+//! # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; }
+//! # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
+//! #
+//! use iced::widget::{column, radio};
+//!
+//! struct State {
+//! selection: Option<Choice>,
+//! }
+//!
+//! #[derive(Debug, Clone, Copy)]
+//! enum Message {
+//! RadioSelected(Choice),
+//! }
+//!
+//! #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+//! enum Choice {
+//! A,
+//! B,
+//! C,
+//! All,
+//! }
+//!
+//! fn view(state: &State) -> Element<'_, Message> {
+//! let a = radio(
+//! "A",
+//! Choice::A,
+//! state.selection,
+//! Message::RadioSelected,
+//! );
+//!
+//! let b = radio(
+//! "B",
+//! Choice::B,
+//! state.selection,
+//! Message::RadioSelected,
+//! );
+//!
+//! let c = radio(
+//! "C",
+//! Choice::C,
+//! state.selection,
+//! Message::RadioSelected,
+//! );
+//!
+//! let all = radio(
+//! "All of the above",
+//! Choice::All,
+//! state.selection,
+//! Message::RadioSelected
+//! );
+//!
+//! column![a, b, c, all].into()
+//! }
+//! ```
use crate::core::alignment;
use crate::core::border::{self, Border};
use crate::core::event::{self, Event};
@@ -18,54 +75,59 @@ use crate::core::{
///
/// # Example
/// ```no_run
-/// # type Radio<'a, Message> =
-/// # iced_widget::Radio<'a, Message, iced_widget::Theme, iced_widget::renderer::Renderer>;
+/// # mod iced { pub mod widget { pub use iced_widget::*; } pub use iced_widget::Renderer; pub use iced_widget::core::*; }
+/// # pub type Element<'a, Message> = iced_widget::core::Element<'a, Message, iced_widget::Theme, iced_widget::Renderer>;
/// #
-/// # use iced_widget::column;
-/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
-/// pub enum Choice {
-/// A,
-/// B,
-/// C,
-/// All,
+/// use iced::widget::{column, radio};
+///
+/// struct State {
+/// selection: Option<Choice>,
/// }
///
/// #[derive(Debug, Clone, Copy)]
-/// pub enum Message {
+/// enum Message {
/// RadioSelected(Choice),
/// }
///
-/// let selected_choice = Some(Choice::A);
+/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+/// enum Choice {
+/// A,
+/// B,
+/// C,
+/// All,
+/// }
///
-/// let a = Radio::new(
-/// "A",
-/// Choice::A,
-/// selected_choice,
-/// Message::RadioSelected,
-/// );
+/// fn view(state: &State) -> Element<'_, Message> {
+/// let a = radio(
+/// "A",
+/// Choice::A,
+/// state.selection,
+/// Message::RadioSelected,
+/// );
///
-/// let b = Radio::new(
-/// "B",
-/// Choice::B,
-/// selected_choice,
-/// Message::RadioSelected,
-/// );
+/// let b = radio(
+/// "B",
+/// Choice::B,
+/// state.selection,
+/// Message::RadioSelected,
+/// );
///
-/// let c = Radio::new(
-/// "C",
-/// Choice::C,
-/// selected_choice,
-/// Message::RadioSelected,
-/// );
+/// let c = radio(
+/// "C",
+/// Choice::C,
+/// state.selection,
+/// Message::RadioSelected,
+/// );
///
-/// let all = Radio::new(
-/// "All of the above",
-/// Choice::All,
-/// selected_choice,
-/// Message::RadioSelected
-/// );
+/// let all = radio(
+/// "All of the above",
+/// Choice::All,
+/// state.selection,
+/// Message::RadioSelected
+/// );
///
-/// let content = column![a, b, c, all];
+/// column![a, b, c, all].into()
+/// }
/// ```
#[allow(missing_debug_implementations)]
pub struct Radio<'a, Message, Theme = crate::Theme, Renderer = crate::Renderer>