diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2026-02-05 14:20:35 +0100 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2026-02-05 14:21:32 +0100 |
| commit | 5eddb62f3cae4740680eaa81d448c3eeda88068a (patch) | |
| tree | f45e6b7afaa8ed3a2a5dea5e65685f83017c0eb7 /src/text.rs | |
| parent | chore: bump MSRV to match iced's (diff) | |
| download | iced_selection-5eddb62f3cae4740680eaa81d448c3eeda88068a.tar.gz | |
feat: make click interval for double & triple clicks customizable
Diffstat (limited to '')
| -rw-r--r-- | src/text.rs | 19 |
1 files changed, 16 insertions, 3 deletions
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<Renderer::Font>, + click_interval: Option<Duration>, 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<Dragging>, - last_click: Option<mouse::Click>, + last_click: Option<click::Click>, keyboard_modifiers: keyboard::Modifiers, visual_lines_bounds: Vec<core::Rectangle>, } @@ -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 |
