From 6dbaa00a677a374487fece3d345ab0185447c7af Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Fri, 27 Oct 2023 20:40:54 +0100 Subject: [PATCH] give double click some tolerance --- src/views/virtual_list.rs | 2 +- src/window_handle.rs | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/views/virtual_list.rs b/src/views/virtual_list.rs index 397050e3..ca6c91e7 100644 --- a/src/views/virtual_list.rs +++ b/src/views/virtual_list.rs @@ -112,7 +112,7 @@ where } else { usize::MAX }; - before_size = item_size * start as f64; + before_size = item_size * (start.min(total_len)) as f64; for item in items_vector.slice(start..end) { items.push(item); diff --git a/src/window_handle.rs b/src/window_handle.rs index b1bd56c1..cc65a9b6 100644 --- a/src/window_handle.rs +++ b/src/window_handle.rs @@ -57,7 +57,7 @@ pub(crate) struct WindowHandle { pub(crate) modifiers: ModifiersState, pub(crate) cursor_position: Point, pub(crate) window_position: Point, - pub(crate) last_pointer_down: Option<(u8, Instant)>, + pub(crate) last_pointer_down: Option<(u8, Point, Instant)>, #[cfg(target_os = "linux")] pub(crate) context_menu: RwSignal>, } @@ -337,7 +337,6 @@ impl WindowHandle { pub(crate) fn pointer_move(&mut self, pos: Point) { if self.cursor_position != pos { - self.last_pointer_down = None; self.cursor_position = pos; let event = PointerMoveEvent { pos, @@ -389,18 +388,21 @@ impl WindowHandle { pub(crate) fn mouse_input(&mut self, button: MouseButton, state: ElementState) { let button: PointerButton = button.into(); let count = if state.is_pressed() && button.is_primary() { - if let Some((count, instant)) = self.last_pointer_down.as_mut() { + if let Some((count, last_pos, instant)) = self.last_pointer_down.as_mut() { if *count == 4 { *count = 1; - } else if instant.elapsed().as_millis() < 500 { + } else if instant.elapsed().as_millis() < 500 + && last_pos.distance(self.cursor_position) < 4.0 + { *count += 1; } else { *count = 1; } *instant = Instant::now(); + *last_pos = self.cursor_position; *count } else { - self.last_pointer_down = Some((1, Instant::now())); + self.last_pointer_down = Some((1, self.cursor_position, Instant::now())); 1 } } else { @@ -420,12 +422,6 @@ impl WindowHandle { self.event(Event::PointerUp(event)); } } - // fire an pointer move event in case there's view change - // and hover needs to be updated - self.event(Event::PointerMove(PointerMoveEvent { - pos: self.cursor_position, - modifiers: self.modifiers, - })); } pub(crate) fn focused(&mut self, focused: bool) {