aboutsummaryrefslogtreecommitdiff
path: root/src/text/rich.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/text/rich.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/text/rich.rs b/src/text/rich.rs
index 865f64a..c148566 100644
--- a/src/text/rich.rs
+++ b/src/text/rich.rs
@@ -1,6 +1,7 @@
use iced_widget::graphics::text::Paragraph;
use iced_widget::graphics::text::cosmic_text;
+use crate::click;
use crate::core::alignment;
use crate::core::clipboard;
use crate::core::keyboard;
@@ -9,6 +10,7 @@ use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::text::{Paragraph as _, Span};
+use crate::core::time::Duration;
use crate::core::touch;
use crate::core::widget::text::{Alignment, LineHeight, Shaping, Wrapping};
use crate::core::widget::tree::{self, Tree};
@@ -40,6 +42,7 @@ pub struct Rich<
align_x: Alignment,
align_y: alignment::Vertical,
wrapping: Wrapping,
+ click_interval: Option<Duration>,
class: Theme::Class<'a>,
on_link_click: Option<Box<dyn Fn(Link) -> Message + 'a>>,
on_link_hover: Option<Box<dyn Fn(Link) -> Message + 'a>>,
@@ -66,6 +69,7 @@ where
align_x: Alignment::Default,
align_y: alignment::Vertical::Top,
wrapping: Wrapping::default(),
+ click_interval: None,
class: Theme::default(),
on_link_click: None,
on_link_hover: None,
@@ -140,6 +144,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 message that will be produced when a link of the [`Rich`] text
/// is clicked.
///
@@ -223,7 +236,7 @@ struct State<Link> {
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>,
}
@@ -588,10 +601,11 @@ where
}
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
@@ -599,7 +613,7 @@ where
.unwrap_or((0, 0));
match click.kind() {
- mouse::click::Kind::Single => {
+ click::Kind::Single => {
let new_end = SelectionEnd { line, index };
if state.keyboard_modifiers.shift() {
@@ -610,7 +624,7 @@ where
state.dragging = Some(Dragging::Grapheme);
}
- mouse::click::Kind::Double => {
+ click::Kind::Double => {
state.selection.select_word(
line,
index,
@@ -618,7 +632,7 @@ where
);
state.dragging = Some(Dragging::Word);
}
- mouse::click::Kind::Triple => {
+ click::Kind::Triple => {
state.selection.select_line(line, &state.paragraph);
state.dragging = Some(Dragging::Line);
}