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

@ -109,6 +109,7 @@ pub struct Checkbox<
text_line_height: text::LineHeight,
text_shaping: text::Shaping,
text_wrapping: text::Wrapping,
text_ellipsize: text::Ellipsize,
font: Option<Renderer::Font>,
icon: Icon<Renderer::Font>,
class: Theme::Class<'a>,
@ -145,6 +146,7 @@ where
text_line_height: text::LineHeight::default(),
text_shaping: text::Shaping::default(),
text_wrapping: text::Wrapping::default(),
text_ellipsize: text::Ellipsize::default(),
font: None,
icon: Icon {
font: Renderer::ICON_FONT,
@ -351,6 +353,7 @@ where
align_y: alignment::Vertical::Top,
shaping: self.text_shaping,
wrapping: self.text_wrapping,
ellipsize: self.text_ellipsize,
},
)
} else {
@ -477,6 +480,7 @@ where
align_y: alignment::Vertical::Center,
shaping: *shaping,
wrapping: text::Wrapping::default(),
ellipsize: text::Ellipsize::default(),
},
bounds.center(),
style.icon_color,

View file

@ -576,6 +576,7 @@ where
align_y: alignment::Vertical::Center,
shaping: self.text_shaping,
wrapping: text::Wrapping::default(),
ellipsize: text::Ellipsize::default(),
},
Point::new(bounds.x + self.padding.left, bounds.center_y()),
if is_selected {

View file

@ -171,6 +171,7 @@ pub struct PickList<
text_line_height: text::LineHeight,
text_shaping: text::Shaping,
text_wrap: text::Wrapping,
text_ellipsize: text::Ellipsize,
font: Option<Renderer::Font>,
handle: Handle<Renderer::Font>,
class: <Theme as Catalog>::Class<'a>,
@ -209,6 +210,7 @@ where
text_line_height: text::LineHeight::default(),
text_shaping: text::Shaping::Advanced,
text_wrap: text::Wrapping::default(),
text_ellipsize: text::Ellipsize::default(),
font: None,
handle: Handle::default(),
class: <Theme as Catalog>::default(),
@ -392,6 +394,7 @@ where
align_y: alignment::Vertical::Center,
shaping: self.text_shaping,
wrapping: self.text_wrap,
ellipsize: self.text_ellipsize,
};
for (option, paragraph) in options.iter().zip(state.options.iter_mut())
@ -614,6 +617,7 @@ where
text::LineHeight::default(),
text::Shaping::Basic,
text::Wrapping::default(),
text::Ellipsize::default(),
)),
Handle::Static(Icon {
font,
@ -622,9 +626,16 @@ where
line_height,
shaping,
wrap,
}) => {
Some((*font, *code_point, *size, *line_height, *shaping, *wrap))
}
ellipsize,
}) => Some((
*font,
*code_point,
*size,
*line_height,
*shaping,
*wrap,
*ellipsize,
)),
Handle::Dynamic { open, closed } => {
if state.is_open {
Some((
@ -634,6 +645,7 @@ where
open.line_height,
open.shaping,
open.wrap,
open.ellipsize,
))
} else {
Some((
@ -643,14 +655,22 @@ where
closed.line_height,
closed.shaping,
closed.wrap,
closed.ellipsize,
))
}
}
Handle::None => None,
};
if let Some((font, code_point, size, line_height, shaping, wrap)) =
handle
if let Some((
font,
code_point,
size,
line_height,
shaping,
wrap,
ellipsize,
)) = handle
{
let size = size.unwrap_or_else(|| renderer.default_size());
@ -668,6 +688,7 @@ where
align_y: alignment::Vertical::Center,
shaping,
wrapping: wrap,
ellipsize: ellipsize,
},
Point::new(
bounds.x + bounds.width - self.padding.right,
@ -698,6 +719,7 @@ where
align_y: alignment::Vertical::Center,
shaping: self.text_shaping,
wrapping: self.text_wrap,
ellipsize: self.text_ellipsize,
},
Point::new(bounds.x + self.padding.left, bounds.center_y()),
if selected.is_some() {
@ -851,6 +873,8 @@ pub struct Icon<Font> {
pub shaping: text::Shaping,
/// The wrap mode of the icon.
pub wrap: text::Wrapping,
/// The ellipsize mode of the icon.
pub ellipsize: text::Ellipsize,
}
/// The possible status of a [`PickList`].

View file

@ -144,6 +144,7 @@ where
text_line_height: text::LineHeight,
text_shaping: text::Shaping,
text_wrapping: text::Wrapping,
text_ellipsize: text::Ellipsize,
font: Option<Renderer::Font>,
class: Theme::Class<'a>,
last_status: Option<Status>,
@ -190,6 +191,7 @@ where
text_line_height: text::LineHeight::default(),
text_shaping: text::Shaping::Advanced,
text_wrapping: text::Wrapping::default(),
text_ellipsize: text::Ellipsize::default(),
font: None,
class: Theme::default(),
last_status: None,
@ -241,6 +243,12 @@ where
self
}
/// Sets the [`text::Ellipsize`] strategy of the [`Radio`] button.
pub fn text_ellipsize(mut self, ellipsize: text::Ellipsize) -> Self {
self.text_ellipsize = ellipsize;
self
}
/// Sets the text font of the [`Radio`] button.
pub fn font(mut self, font: impl Into<Renderer::Font>) -> Self {
self.font = Some(font.into());
@ -318,6 +326,7 @@ where
align_y: alignment::Vertical::Top,
shaping: self.text_shaping,
wrapping: self.text_wrapping,
ellipsize: self.text_ellipsize,
},
)
},

View file

@ -1847,6 +1847,7 @@ where
align_y: alignment::Vertical::Center,
shaping: text::Shaping::Basic,
wrapping: text::Wrapping::None,
ellipsize: text::Ellipsize::None,
};
if self.vertical {

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 => {

View file

@ -41,7 +41,7 @@ use crate::core::mouse;
use crate::core::renderer;
use crate::core::text::editor::Editor as _;
use crate::core::text::highlighter::{self, Highlighter};
use crate::core::text::{self, LineHeight, Text, Wrapping};
use crate::core::text::{self, Ellipsize, LineHeight, Text, Wrapping};
use crate::core::theme;
use crate::core::time::{Duration, Instant};
use crate::core::widget::operation;
@ -129,6 +129,7 @@ pub struct TextEditor<
max_height: f32,
padding: Padding,
wrapping: Wrapping,
ellipsize: text::Ellipsize,
class: Theme::Class<'a>,
key_binding: Option<Box<dyn Fn(KeyPress) -> Option<Binding<Message>> + 'a>>,
on_edit: Option<Box<dyn Fn(Action) -> Message + 'a>>,
@ -162,6 +163,7 @@ where
padding: Padding::new(5.0),
wrapping: Wrapping::default(),
class: <Theme as Catalog>::default(),
ellipsize: Ellipsize::default(),
key_binding: None,
on_edit: None,
highlighter_settings: (),
@ -308,6 +310,7 @@ where
max_height: self.max_height,
padding: self.padding,
wrapping: self.wrapping,
ellipsize: self.ellipsize,
class: self.class,
key_binding: self.key_binding,
on_edit: self.on_edit,
@ -1011,6 +1014,7 @@ where
align_y: alignment::Vertical::Top,
shaping: text::Shaping::Advanced,
wrapping: self.wrapping,
ellipsize: self.ellipsize,
},
text_bounds.position(),
style.placeholder,

View file

@ -321,6 +321,7 @@ where
align_y: alignment::Vertical::Center,
shaping: text::Shaping::Advanced,
wrapping: text::Wrapping::default(),
ellipsize: text::Ellipsize::default(),
};
let _ = state.placeholder.update(placeholder_text);
@ -346,6 +347,7 @@ where
align_y: alignment::Vertical::Center,
shaping: text::Shaping::Advanced,
wrapping: text::Wrapping::default(),
ellipsize: text::Ellipsize::default(),
};
let _ = state.icon.update(icon_text);
@ -1687,6 +1689,7 @@ fn replace_paragraph<Renderer>(
align_y: alignment::Vertical::Center,
shaping: text::Shaping::Advanced,
wrapping: text::Wrapping::default(),
ellipsize: text::Ellipsize::default(),
});
}

View file

@ -112,6 +112,7 @@ pub struct Toggler<
text_alignment: text::Alignment,
text_shaping: text::Shaping,
text_wrapping: text::Wrapping,
text_ellipsize: text::Ellipsize,
spacing: f32,
font: Option<Renderer::Font>,
class: Theme::Class<'a>,
@ -150,6 +151,7 @@ where
text_line_height: text::LineHeight::default(),
text_alignment: text::Alignment::Default,
text_wrapping: text::Wrapping::default(),
text_ellipsize: text::Ellipsize::default(),
spacing: Self::DEFAULT_SIZE / 2.0,
text_shaping: text::Shaping::Advanced,
font: None,
@ -237,6 +239,12 @@ where
self
}
/// Sets the [`text::Ellipsize`] strategy of the [`Toggler`].
pub fn text_ellipsize(mut self, ellipsize: text::Ellipsize) -> Self {
self.text_ellipsize = ellipsize;
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;
@ -362,6 +370,7 @@ where
align_y: alignment::Vertical::Top,
shaping: self.text_shaping,
wrapping: self.text_wrapping,
ellipsize: self.text_ellipsize,
},
)
} else {