use mouse event count for double click

This commit is contained in:
Dongdong Zhou 2022-05-18 15:48:21 +01:00
parent ed750a4dc3
commit 15b2bffeb4
1 changed files with 3 additions and 6 deletions

View File

@ -23,7 +23,6 @@
pub struct Title { pub struct Title {
mouse_pos: Point, mouse_pos: Point,
commands: Vec<(Rect, Command)>, commands: Vec<(Rect, Command)>,
last_mouse_up: Instant,
} }
impl Title { impl Title {
@ -31,7 +30,6 @@ pub fn new() -> Self {
Self { Self {
mouse_pos: Point::ZERO, mouse_pos: Point::ZERO,
commands: Vec::new(), commands: Vec::new(),
last_mouse_up: Instant::now(),
} }
} }
@ -81,9 +79,9 @@ fn event(
Event::MouseDown(mouse_event) => { Event::MouseDown(mouse_event) => {
self.mouse_down(ctx, mouse_event); self.mouse_down(ctx, mouse_event);
} }
Event::MouseUp(_) => {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
if self.last_mouse_up.elapsed().as_millis() < 500 { Event::MouseUp(mouse_event) => {
if mouse_event.count >= 2 {
let state = match ctx.window().get_window_state() { let state = match ctx.window().get_window_state() {
WindowState::Maximized => WindowState::Restored, WindowState::Maximized => WindowState::Restored,
WindowState::Restored => WindowState::Maximized, WindowState::Restored => WindowState::Maximized,
@ -95,7 +93,6 @@ fn event(
.to(Target::Window(data.window_id)), .to(Target::Window(data.window_id)),
) )
} }
self.last_mouse_up = Instant::now();
} }
_ => {} _ => {}
} }