Browse Source

Add `PointerState::button_double_clicked()` and `PointerState::button_triple_clicked()`. (#1907)

Co-authored-by: eranfu <eranfu@tencent.com>
pull/1263/merge
eranfu 2 years ago
committed by GitHub
parent
commit
38a67f8646
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 14
      egui/src/input_state.rs

1
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)).

14
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)

Loading…
Cancel
Save