diff options
| author | 2020-02-23 01:23:57 +0100 | |
|---|---|---|
| committer | 2020-02-23 01:23:57 +0100 | |
| commit | 883843a72df44bf420f43771165dd8e7c9312e17 (patch) | |
| tree | 0ff062852b3e61de6f8ae2df20184cbd3c2eb6ee /native | |
| parent | f72b1f8c45b55c48210161568ee8a916706ec00a (diff) | |
| download | iced-883843a72df44bf420f43771165dd8e7c9312e17.tar.gz iced-883843a72df44bf420f43771165dd8e7c9312e17.tar.bz2 iced-883843a72df44bf420f43771165dd8e7c9312e17.zip | |
max time window for double click
Diffstat (limited to '')
| -rw-r--r-- | native/src/widget/text_input.rs | 21 | 
1 files changed, 20 insertions, 1 deletions
| diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 96f9d96f..22913289 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -10,7 +10,10 @@ use crate::{      Rectangle, Size, Widget,  }; -use std::u32; +use std::{ +    time::{Duration, SystemTime}, +    u32, +};  use unicode_segmentation::UnicodeSegmentation;  /// A field that can be filled with text. @@ -215,6 +218,15 @@ where                              .last_position                              .unwrap_or(Point { x: 0.0, y: 0.0 })                          && self.state.click_count < 2 +                        && SystemTime::now() +                            .duration_since( +                                self.state +                                    .last_timestamp +                                    .unwrap_or(SystemTime::now()), +                            ) +                            .unwrap_or(Duration::from_secs(1)) +                            .as_millis() +                            <= 500                      {                          self.state.click_count += 1; @@ -236,6 +248,9 @@ where                                  end: self.value.len(),                              }                          } + +                        self.state.last_timestamp = +                            Option::from(SystemTime::now());                      } else if target > 0.0 {                          let value = if self.is_secure {                              self.value.secure() @@ -266,6 +281,8 @@ where                          self.state.click_count = 0;                          self.state.last_position =                              Option::from(cursor_position); +                        self.state.last_timestamp = +                            Option::from(SystemTime::now());                      } else {                          self.state.click_count = 0;                          self.state.last_position = @@ -637,6 +654,7 @@ pub struct State {      /// Double- / Tripleclick      click_count: usize,      last_position: Option<Point>, +    last_timestamp: Option<std::time::SystemTime>,      // TODO: Add stateful horizontal scrolling offset  } @@ -724,6 +742,7 @@ impl State {              cursor_position: Cursor::Index(usize::MAX),              click_count: 0,              last_position: None, +            last_timestamp: None,          }      } | 
