From 5eddb62f3cae4740680eaa81d448c3eeda88068a Mon Sep 17 00:00:00 2001 From: Polesznyák Márk Date: Thu, 5 Feb 2026 14:20:35 +0100 Subject: feat: make click interval for double & triple clicks customizable --- src/text.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/text.rs') diff --git a/src/text.rs b/src/text.rs index 851e77b..72bdbf8 100644 --- a/src/text.rs +++ b/src/text.rs @@ -24,15 +24,16 @@ pub use rich::Rich; use text::{Alignment, LineHeight, Shaping, Wrapping}; pub use text::{Fragment, Highlighter, IntoFragment, Span}; +use crate::click; use crate::core::alignment; use crate::core::clipboard; use crate::core::keyboard::{self, key}; use crate::core::layout; use crate::core::mouse; -use crate::core::mouse::click; use crate::core::renderer; use crate::core::text; use crate::core::text::paragraph::Paragraph as _; +use crate::core::time::Duration; use crate::core::touch; use crate::core::widget::Operation; use crate::core::widget::text::Format; @@ -69,6 +70,7 @@ pub struct Text< { fragment: Fragment<'a>, format: Format, + click_interval: Option, class: Theme::Class<'a>, } @@ -82,6 +84,7 @@ where Self { fragment: fragment.into_fragment(), format: Format::default(), + click_interval: None, class: Theme::default(), } } @@ -150,6 +153,15 @@ where self } + /// The maximum delay required for two consecutive clicks to be interpreted as a double click + /// (also applies to triple clicks). + /// + /// Defaults to 300ms. + pub fn click_interval(mut self, click_interval: Duration) -> Self { + self.click_interval = Some(click_interval); + self + } + /// Sets the style of the [`Text`]. #[must_use] pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self @@ -176,7 +188,7 @@ pub struct State { is_hovered: bool, selection: Selection, dragging: Option, - last_click: Option, + last_click: Option, keyboard_modifiers: keyboard::Modifiers, visual_lines_bounds: Vec, } @@ -393,10 +405,11 @@ where Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) | Event::Touch(touch::Event::FingerPressed { .. }) => { if let Some(position) = cursor.position_over(bounds) { - let click = mouse::Click::new( + let click = click::Click::new( position, mouse::Button::Left, state.last_click, + self.click_interval, ); let (line, index) = state -- cgit v1.2.3