diff options
Diffstat (limited to '')
| -rw-r--r-- | src/text/rich.rs | 24 |
1 files changed, 17 insertions, 7 deletions
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 { |
