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.
This commit is contained in:
Miles Silberling-Cook 2024-10-31 10:44:34 -04:00 committed by GitHub
parent 03372e590d
commit 9a0c9b9e8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<PointerInput>,