aboutsummaryrefslogtreecommitdiff
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
parentchore: update as necessary for upstream iced changes (PR#3238) (diff)
downloadiced_selection-f6472443910a959dd6214a1e0640700e4ef913b8.tar.gz
feat: add ellipsis support
-rw-r--r--src/text.rs23
-rw-r--r--src/text/rich.rs24
2 files changed, 31 insertions, 16 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 {
diff --git a/src/text/rich.rs b/src/text/rich.rs
index 60e2637..9bd7d9f 100644
--- a/src/text/rich.rs
+++ b/src/text/rich.rs
@@ -8,7 +8,7 @@ use crate::core::keyboard::key;
use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
-use crate::core::text::{Paragraph as _, Span};
+use crate::core::text::{Ellipsis, Paragraph as _, Span};
use crate::core::time::Duration;
use crate::core::touch;
use crate::core::widget::text::{Alignment, LineHeight, Shaping, Wrapping};
@@ -21,6 +21,7 @@ use crate::selection::{Selection, SelectionEnd};
use crate::text::{Catalog, Dragging, Style, StyleFn};
/// A bunch of [`Rich`] text.
+#[must_use]
pub struct Rich<
'a,
Link,
@@ -41,6 +42,7 @@ pub struct Rich<
align_x: Alignment,
align_y: alignment::Vertical,
wrapping: Wrapping,
+ ellipsis: Ellipsis,
click_interval: Option<Duration>,
class: Theme::Class<'a>,
on_link_click: Option<Box<dyn Fn(Link) -> Message + 'a>>,
@@ -68,6 +70,7 @@ where
align_x: Alignment::Default,
align_y: alignment::Vertical::Top,
wrapping: Wrapping::default(),
+ ellipsis: Ellipsis::None,
click_interval: None,
class: Theme::default(),
on_link_click: None,
@@ -143,6 +146,12 @@ where
self
}
+ /// Sets the [`Ellipsis`] strategy of the [`Rich`] text.
+ pub fn ellipsis(mut self, ellipsis: Ellipsis) -> Self {
+ self.ellipsis = ellipsis;
+ self
+ }
+
/// The maximum delay required for two consecutive clicks to be interpreted as a double click
/// (also applies to triple clicks).
///
@@ -197,7 +206,6 @@ where
}
/// Sets the default style of the [`Rich`] text.
- #[must_use]
pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self
where
Theme::Class<'a>: From<StyleFn<'a, Theme>>,
@@ -207,7 +215,6 @@ where
}
/// Sets the default style class of the [`Rich`] text.
- #[must_use]
pub fn class(mut self, class: impl Into<Theme::Class<'a>>) -> Self {
self.class = class.into();
self
@@ -407,6 +414,7 @@ where
self.align_x,
self.align_y,
self.wrapping,
+ self.ellipsis,
)
}
@@ -884,6 +892,7 @@ fn layout<Link, Renderer>(
align_x: Alignment,
align_y: alignment::Vertical,
wrapping: Wrapping,
+ ellipsis: Ellipsis,
) -> layout::Node
where
Link: Clone,
@@ -905,6 +914,7 @@ where
align_y,
shaping: Shaping::Advanced,
wrapping,
+ ellipsis,
hint_factor: renderer.scale_factor(),
};
@@ -924,6 +934,7 @@ where
align_y,
shaping: Shaping::Advanced,
wrapping,
+ ellipsis,
hint_factor: renderer.scale_factor(),
}) {
core::text::Difference::None => {}
@@ -993,10 +1004,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 {