diff --git a/CHANGELOG.md b/CHANGELOG.md index 54febf60f..e34b7ddc8 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 ed40c5cab..143fd6c31 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)