diff options
Diffstat (limited to 'widget/src/toggler.rs')
-rw-r--r-- | widget/src/toggler.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 821e2526..f7b3078c 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -40,13 +40,14 @@ pub struct Toggler< { is_toggled: bool, on_toggle: Box<dyn Fn(bool) -> Message + 'a>, - label: Option<String>, + label: Option<text::Fragment<'a>>, width: Length, size: f32, text_size: Option<Pixels>, text_line_height: text::LineHeight, text_alignment: alignment::Horizontal, text_shaping: text::Shaping, + text_wrapping: text::Wrapping, spacing: f32, font: Option<Renderer::Font>, class: Theme::Class<'a>, @@ -69,7 +70,7 @@ where /// will receive the new state of the [`Toggler`] and must produce a /// `Message`. pub fn new<F>( - label: impl Into<Option<String>>, + label: Option<impl text::IntoFragment<'a>>, is_toggled: bool, f: F, ) -> Self @@ -79,13 +80,14 @@ where Toggler { is_toggled, on_toggle: Box::new(f), - label: label.into(), + label: label.map(text::IntoFragment::into_fragment), width: Length::Shrink, size: Self::DEFAULT_SIZE, text_size: None, text_line_height: text::LineHeight::default(), text_alignment: alignment::Horizontal::Left, - text_shaping: text::Shaping::Basic, + text_shaping: text::Shaping::default(), + text_wrapping: text::Wrapping::default(), spacing: Self::DEFAULT_SIZE / 2.0, font: None, class: Theme::default(), @@ -131,6 +133,12 @@ where self } + /// Sets the [`text::Wrapping`] strategy of the [`Toggler`]. + pub fn text_wrapping(mut self, wrapping: text::Wrapping) -> Self { + self.text_wrapping = wrapping; + self + } + /// Sets the spacing between the [`Toggler`] and the text. pub fn spacing(mut self, spacing: impl Into<Pixels>) -> Self { self.spacing = spacing.into().0; @@ -216,6 +224,7 @@ where self.text_alignment, alignment::Vertical::Top, self.text_shaping, + self.text_wrapping, ) } else { layout::Node::new(Size::ZERO) |