aboutsummaryrefslogtreecommitdiff
path: root/src/text
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/text.rs19
-rw-r--r--src/text/rich.rs24
2 files changed, 35 insertions, 8 deletions
diff --git a/src/text.rs b/src/text.rs
index 911c0cc..3915e0e 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
diff --git a/src/text/rich.rs b/src/text/rich.rs
index 44c6f3e..e0f2a1c 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.
pub fn on_link_click(
@@ -219,7 +232,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>,
}
@@ -584,10 +597,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
@@ -595,7 +609,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() {
@@ -606,7 +620,7 @@ where
state.dragging = Some(Dragging::Grapheme);
}
- mouse::click::Kind::Double => {
+ click::Kind::Double => {
state.selection.select_word(
line,
index,
@@ -614,7 +628,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);
}