feat: add Ellipsize to widgets

This commit is contained in:
Hojjat 2026-02-19 09:27:37 -07:00 committed by Ashley Wulber
parent f2ef716ad5
commit cc670e1966
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
18 changed files with 181 additions and 9 deletions

View file

@ -4,7 +4,8 @@ use crate::core::mouse;
use crate::core::renderer;
use crate::core::text::{Paragraph, Span};
use crate::core::widget::text::{
self, Alignment, Catalog, LineHeight, Shaping, Style, StyleFn, Wrapping,
self, Alignment, Catalog, Ellipsize, LineHeight, Shaping, Style, StyleFn,
Wrapping,
};
use crate::core::widget::tree::{self, Tree};
use crate::core::{
@ -33,6 +34,7 @@ pub struct Rich<
align_x: Alignment,
align_y: alignment::Vertical,
wrapping: Wrapping,
ellipsize: Ellipsize,
class: Theme::Class<'a>,
hovered_link: Option<usize>,
on_link_click: Option<Box<dyn Fn(Link) -> Message + 'a>>,
@ -58,6 +60,7 @@ where
align_x: Alignment::Default,
align_y: alignment::Vertical::Top,
wrapping: Wrapping::default(),
ellipsize: Ellipsize::default(),
class: Theme::default(),
hovered_link: None,
on_link_click: None,
@ -145,6 +148,12 @@ where
self
}
/// Sets the [`Ellipsize`] strategy of the [`Rich`] text.
pub fn ellipsize(mut self, ellipsize: Ellipsize) -> Self {
self.ellipsize = ellipsize;
self
}
/// Sets the default style of the [`Rich`] text.
#[must_use]
pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self
@ -247,6 +256,7 @@ where
self.align_x,
self.align_y,
self.wrapping,
self.ellipsize,
)
}
@ -476,6 +486,7 @@ fn layout<Link, Renderer>(
align_x: Alignment,
align_y: alignment::Vertical,
wrapping: Wrapping,
ellipsize: Ellipsize,
) -> layout::Node
where
Link: Clone,
@ -497,6 +508,7 @@ where
align_y,
shaping: Shaping::Advanced,
wrapping,
ellipsize,
};
if state.spans != spans {
@ -514,6 +526,7 @@ where
align_y,
shaping: Shaping::Advanced,
wrapping,
ellipsize,
}) {
core::text::Difference::None => {}
core::text::Difference::Bounds => {