aboutsummaryrefslogtreecommitdiff
path: root/src/text.rs
diff options
context:
space:
mode:
authorPolesznyák Márk <contact@pml68.dev>2026-02-22 19:53:19 +0100
committerPolesznyák Márk <contact@pml68.dev>2026-03-12 20:19:39 +0100
commitf6472443910a959dd6214a1e0640700e4ef913b8 (patch)
tree6202150d36b320fcf240f040b035a73204bc5b1f /src/text.rs
parentchore: update as necessary for upstream iced changes (PR#3238) (diff)
downloadiced_selection-f6472443910a959dd6214a1e0640700e4ef913b8.tar.gz
feat: add ellipsis support
Diffstat (limited to '')
-rw-r--r--src/text.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/text.rs b/src/text.rs
index 433cf60..3b6b11d 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -21,7 +21,7 @@ mod rich;
use iced_widget::graphics::text::Paragraph;
use iced_widget::graphics::text::cosmic_text;
pub use rich::Rich;
-use text::{Alignment, LineHeight, Shaping, Wrapping};
+use text::{Alignment, Ellipsis, LineHeight, Shaping, Wrapping};
pub use text::{Fragment, Highlighter, IntoFragment, Span};
use crate::click;
@@ -31,7 +31,7 @@ use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::text;
-use crate::core::text::paragraph::Paragraph as _;
+use crate::core::text::Paragraph as _;
use crate::core::time::Duration;
use crate::core::touch;
use crate::core::widget::Operation;
@@ -59,6 +59,7 @@ use crate::selection::{Selection, SelectionEnd};
/// .into()
/// }
/// ```
+#[must_use]
pub struct Text<
'a,
Theme = iced_widget::Theme,
@@ -152,6 +153,12 @@ where
self
}
+ /// Sets the [`Ellipsis`] strategy of the [`Text`].
+ pub fn ellipsis(mut self, ellipsis: Ellipsis) -> Self {
+ self.format.ellipsis = ellipsis;
+ self
+ }
+
/// The maximum delay required for two consecutive clicks to be interpreted as a double click
/// (also applies to triple clicks).
///
@@ -162,7 +169,6 @@ where
}
/// Sets the style of the [`Text`].
- #[must_use]
pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self
where
Theme::Class<'a>: From<StyleFn<'a, Theme>>,
@@ -172,7 +178,6 @@ where
}
/// Sets the style class of the [`Text`].
- #[must_use]
pub fn class(mut self, class: impl Into<Theme::Class<'a>>) -> Self {
self.class = class.into();
self
@@ -719,6 +724,7 @@ where
align_y: format.align_y,
shaping: format.shaping,
wrapping: format.wrapping,
+ ellipsis: format.ellipsis,
hint_factor: renderer.scale_factor(),
});
@@ -818,7 +824,7 @@ impl Catalog for Theme {
pub fn default(theme: &Theme) -> Style {
Style {
color: None,
- selection: theme.extended_palette().primary.weak.color,
+ selection: theme.palette().primary.weak.color,
}
}
@@ -840,10 +846,9 @@ fn highlight_line(
.map(move |(line_nr, visual_line)| {
if line_nr == 0 {
let current_diff = previous_diff
- + visual_line
- .glyphs
- .iter()
- .fold(0, |d, g| d + g.start.abs_diff(g.end) - 1);
+ + visual_line.glyphs.iter().fold(0, |d, g| {
+ (d + g.start.abs_diff(g.end)).saturating_sub(1)
+ });
previous_diff = current_diff;
0
} else {