From f98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 4 Sep 2024 21:25:59 +0200 Subject: Add `text::Wrapping` support Co-authored-by: Neeraj Jaiswal --- widget/src/toggler.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'widget/src/toggler.rs') 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 Message + 'a>, - label: Option, + label: Option>, width: Length, size: f32, text_size: Option, text_line_height: text::LineHeight, text_alignment: alignment::Horizontal, text_shaping: text::Shaping, + text_wrapping: text::Wrapping, spacing: f32, font: Option, 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( - label: impl Into>, + label: Option>, 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) -> 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) -- cgit