summaryrefslogtreecommitdiffstats
path: root/widget/src/toggler.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-04 21:25:59 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-09-04 21:26:47 +0200
commitf98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7 (patch)
tree8fb3e8b470bff711e0ca2f1bf120ab6c66ba9a9d /widget/src/toggler.rs
parent8d826cc662554b337282e7c982383f5db428d7aa (diff)
downloadiced-f98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7.tar.gz
iced-f98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7.tar.bz2
iced-f98328f4f1ee58b6288e4f19d7475e7eeb9a7ba7.zip
Add `text::Wrapping` support
Co-authored-by: Neeraj Jaiswal <neerajj85@gmail.com>
Diffstat (limited to '')
-rw-r--r--widget/src/toggler.rs17
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)