From 38a67f86467f16084443258ae5e7761429c00db2 Mon Sep 17 00:00:00 2001 From: eranfu <1119369173@qq.com> Date: Sun, 14 Aug 2022 22:10:38 +0800 Subject: [PATCH] Add `PointerState::button_double_clicked()` and `PointerState::button_triple_clicked()`. (#1907) Co-authored-by: eranfu --- CHANGELOG.md | 1 + egui/src/input_state.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54febf60..e34b7ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w * Added `Contex::request_repaint_after` ([#1694](https://github.com/emilk/egui/pull/1694)). * `ctrl-h` now acts like backspace in `TextEdit` ([#1812](https://github.com/emilk/egui/pull/1812)). * Added `RawInput::has_focus` which backends can set to indicate whether the UI as a whole has the keyboard focus ([#1859](https://github.com/emilk/egui/pull/1859)). +* Added `PointerState::button_double_clicked()` and `PointerState::button_triple_clicked()` ([#1906](https://github.com/emilk/egui/issues/1906)). ### Changed * MSRV (Minimum Supported Rust Version) is now `1.61.0` ([#1846](https://github.com/emilk/egui/pull/1846)). diff --git a/egui/src/input_state.rs b/egui/src/input_state.rs index ed40c5ca..143fd6c3 100644 --- a/egui/src/input_state.rs +++ b/egui/src/input_state.rs @@ -750,6 +750,20 @@ impl PointerState { .any(|event| matches!(event, &PointerEvent::Pressed { button: b, .. } if button == b)) } + /// Was the button given double clicked this frame? + pub fn button_double_clicked(&self, button: PointerButton) -> bool { + self.pointer_events + .iter() + .any(|event| matches!(&event, PointerEvent::Released(Some(click)) if click.button == button && click.is_double())) + } + + /// Was the button given triple clicked this frame? + pub fn button_triple_clicked(&self, button: PointerButton) -> bool { + self.pointer_events + .iter() + .any(|event| matches!(&event, PointerEvent::Released(Some(click)) if click.button == button && click.is_triple())) + } + /// Was the primary button clicked this frame? pub fn primary_clicked(&self) -> bool { self.button_clicked(PointerButton::Primary)