From 9a0c9b9e8f0408add03c1527a71612ebef34c329 Mon Sep 17 00:00:00 2001 From: Miles Silberling-Cook Date: Thu, 31 Oct 2024 10:44:34 -0400 Subject: [PATCH] Add `button_just_down` and `button_just_up` methods to `PointerInput` (#16176) # Objective Upstream two small methods present in `bevy_mod_picking` but not in `bevy_picking`. There might be a few more of these. --- crates/bevy_picking/src/pointer.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/bevy_picking/src/pointer.rs b/crates/bevy_picking/src/pointer.rs index 7da790c26c..23f544699a 100644 --- a/crates/bevy_picking/src/pointer.rs +++ b/crates/bevy_picking/src/pointer.rs @@ -286,6 +286,26 @@ impl PointerInput { } } + /// Returns true if the `target_button` of this pointer was just pressed. + #[inline] + pub fn button_just_pressed(&self, target_button: PointerButton) -> bool { + if let PointerAction::Pressed { direction, button } = self.action { + direction == PressDirection::Down && button == target_button + } else { + false + } + } + + /// Returns true if the `target_button` of this pointer was just released. + #[inline] + pub fn button_just_released(&self, target_button: PointerButton) -> bool { + if let PointerAction::Pressed { direction, button } = self.action { + direction == PressDirection::Up && button == target_button + } else { + false + } + } + /// Updates pointer entities according to the input events. pub fn receive( mut events: EventReader,