summaryrefslogtreecommitdiffstats
path: root/widget/src/toggler.rs
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/toggler.rs')
-rw-r--r--widget/src/toggler.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs
index a6b2ae92..1c425dc1 100644
--- a/widget/src/toggler.rs
+++ b/widget/src/toggler.rs
@@ -26,7 +26,8 @@ use crate::core::{
///
/// let is_toggled = true;
///
-/// Toggler::new(Some("Toggle me!"), is_toggled)
+/// Toggler::new(is_toggled)
+/// .label("Toggle me!")
/// .on_toggle(Message::TogglerToggled);
/// ```
#[allow(missing_debug_implementations)]
@@ -70,14 +71,11 @@ where
/// * a function that will be called when the [`Toggler`] is toggled. It
/// will receive the new state of the [`Toggler`] and must produce a
/// `Message`.
- pub fn new(
- label: Option<impl text::IntoFragment<'a>>,
- is_toggled: bool,
- ) -> Self {
+ pub fn new(is_toggled: bool) -> Self {
Toggler {
is_toggled,
on_toggle: None,
- label: label.map(text::IntoFragment::into_fragment),
+ label: None,
width: Length::Shrink,
size: Self::DEFAULT_SIZE,
text_size: None,
@@ -91,6 +89,12 @@ where
}
}
+ /// Sets the label of the [`Toggler`].
+ pub fn label(mut self, label: impl text::IntoFragment<'a>) -> Self {
+ self.label = Some(label.into_fragment());
+ self
+ }
+
/// Sets the message that should be produced when a user toggles
/// the [`Toggler`].
///