summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-11 00:20:23 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-11 00:22:39 +0200
commit6e4970c01a9e42621a0ded340dcdccb4204ab5d2 (patch)
tree2f244426201bba5be7c3d3d41f237d062ce722a6
parentc741688b4c52dd2397880ca05b5f9a997d762246 (diff)
downloadiced-6e4970c01a9e42621a0ded340dcdccb4204ab5d2.tar.gz
iced-6e4970c01a9e42621a0ded340dcdccb4204ab5d2.tar.bz2
iced-6e4970c01a9e42621a0ded340dcdccb4204ab5d2.zip
Add `label` method to `Toggler`
-rw-r--r--examples/editor/src/main.rs3
-rw-r--r--examples/styling/src/main.rs3
-rw-r--r--examples/tour/src/main.rs3
-rw-r--r--widget/src/helpers.rs3
-rw-r--r--widget/src/toggler.rs16
5 files changed, 17 insertions, 11 deletions
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs
index c7d7eb26..d55f9bdf 100644
--- a/examples/editor/src/main.rs
+++ b/examples/editor/src/main.rs
@@ -150,7 +150,8 @@ impl Editor {
self.is_dirty.then_some(Message::SaveFile)
),
horizontal_space(),
- toggler(Some("Word Wrap"), self.word_wrap)
+ toggler(self.word_wrap)
+ .label("Word Wrap")
.on_toggle(Message::WordWrapToggled),
pick_list(
highlighter::Theme::ALL,
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs
index 222ab79d..534f5e32 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -77,7 +77,8 @@ impl Styling {
let checkbox = checkbox("Check me!", self.checkbox_value)
.on_toggle(Message::CheckboxToggled);
- let toggler = toggler(Some("Toggle me!"), self.toggler_value)
+ let toggler = toggler(self.toggler_value)
+ .label("Toggle me!")
.on_toggle(Message::TogglerToggled)
.spacing(10);
diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs
index fad5f0b1..d8c0b29a 100644
--- a/examples/tour/src/main.rs
+++ b/examples/tour/src/main.rs
@@ -358,7 +358,8 @@ impl Tour {
.push("A toggler is mostly used to enable or disable something.")
.push(
Container::new(
- toggler(Some("Toggle me to continue..."), self.toggler)
+ toggler(self.toggler)
+ .label("Toggle me to continue...")
.on_toggle(Message::TogglerChanged),
)
.padding([0, 40]),
diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs
index e48ba328..51978823 100644
--- a/widget/src/helpers.rs
+++ b/widget/src/helpers.rs
@@ -767,14 +767,13 @@ where
///
/// [`Toggler`]: crate::Toggler
pub fn toggler<'a, Message, Theme, Renderer>(
- label: Option<impl text::IntoFragment<'a>>,
is_checked: bool,
) -> Toggler<'a, Message, Theme, Renderer>
where
Theme: toggler::Catalog + 'a,
Renderer: core::text::Renderer,
{
- Toggler::new(label, is_checked)
+ Toggler::new(is_checked)
}
/// Creates a new [`TextInput`].
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`].
///