Add text::Wrapping support

Co-authored-by: Neeraj Jaiswal <neerajj85@gmail.com>
This commit is contained in:
Héctor Ramón Jiménez 2024-09-04 21:25:59 +02:00
parent 8d826cc662
commit f98328f4f1
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
21 changed files with 160 additions and 30 deletions

View file

@ -5,7 +5,7 @@ use crate::core::mouse;
use crate::core::renderer;
use crate::core::text::{Paragraph, Span};
use crate::core::widget::text::{
self, Catalog, LineHeight, Shaping, Style, StyleFn,
self, Catalog, LineHeight, Shaping, Style, StyleFn, Wrapping,
};
use crate::core::widget::tree::{self, Tree};
use crate::core::{
@ -29,6 +29,7 @@ where
font: Option<Renderer::Font>,
align_x: alignment::Horizontal,
align_y: alignment::Vertical,
wrapping: Wrapping,
class: Theme::Class<'a>,
}
@ -50,6 +51,7 @@ where
font: None,
align_x: alignment::Horizontal::Left,
align_y: alignment::Vertical::Top,
wrapping: Wrapping::default(),
class: Theme::default(),
}
}
@ -118,6 +120,12 @@ where
self
}
/// Sets the [`Wrapping`] strategy of the [`Rich`] text.
pub fn wrapping(mut self, wrapping: Wrapping) -> Self {
self.wrapping = wrapping;
self
}
/// Sets the default style of the [`Rich`] text.
#[must_use]
pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self
@ -218,6 +226,7 @@ where
self.font,
self.align_x,
self.align_y,
self.wrapping,
)
}
@ -444,6 +453,7 @@ fn layout<Link, Renderer>(
font: Option<Renderer::Font>,
horizontal_alignment: alignment::Horizontal,
vertical_alignment: alignment::Vertical,
wrapping: Wrapping,
) -> layout::Node
where
Link: Clone,
@ -464,6 +474,7 @@ where
horizontal_alignment,
vertical_alignment,
shaping: Shaping::Advanced,
wrapping,
};
if state.spans != spans {
@ -480,6 +491,7 @@ where
horizontal_alignment,
vertical_alignment,
shaping: Shaping::Advanced,
wrapping,
}) {
core::text::Difference::None => {}
core::text::Difference::Bounds => {