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

@ -44,6 +44,9 @@ pub struct Text<Content = String, Font = crate::Font> {
/// The [`Wrapping`] strategy of the [`Text`].
pub wrapping: Wrapping,
/// The [`Ellipsize`] strategy of the [`Text`].
pub ellipsize: Ellipsize,
}
impl<Content, Font> Text<Content, Font>
@ -63,6 +66,7 @@ where
align_y: self.align_y,
shaping: self.shaping,
wrapping: self.wrapping,
ellipsize: self.ellipsize,
}
}
}
@ -192,6 +196,31 @@ pub enum Wrapping {
WordOrGlyph,
}
/// The ellipsizing strategy of some text.
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum Ellipsize {
/// No ellipsizing.
///
/// This is the default.
#[default]
None,
/// Ellipsize at the start of the text.
Start(EllipsizeHeightLimit),
/// Ellipsize in the middle of the text.
Middle(EllipsizeHeightLimit),
/// Ellipsize at the end of the text.
End(EllipsizeHeightLimit),
}
/// The ellipsizing strategy of some text when it exceeds a certain height.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum EllipsizeHeightLimit {
/// The number of lines after which ellipsizing should occur.
Lines(usize),
/// The height limit in pixels
Height(f32),
}
/// The height of a line of text in a paragraph.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineHeight {