diff --git a/crates/bevy_input/src/button_input.rs b/crates/bevy_input/src/button_input.rs index d329470d8b..c781fafe49 100644 --- a/crates/bevy_input/src/button_input.rs +++ b/crates/bevy_input/src/button_input.rs @@ -210,7 +210,17 @@ where /// Returns `true` if any item in `inputs` has just been released. pub fn any_just_released(&self, inputs: impl IntoIterator) -> bool { - inputs.into_iter().any(|it| self.just_released(it)) + inputs.into_iter().any(|input| self.just_released(input)) + } + + /// Returns `true` if all items in `inputs` have just been released. + pub fn all_just_released(&self, inputs: impl IntoIterator) -> bool { + inputs.into_iter().all(|input| self.just_released(input)) + } + + /// Returns `true` if all items in `inputs` have been just pressed. + pub fn all_just_pressed(&self, inputs: impl IntoIterator) -> bool { + inputs.into_iter().all(|input| self.just_pressed(input)) } /// Clears the `just_released` state of the `input` and returns `true` if the `input` has just been released. diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index db0aca53fd..663a0fa3e7 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -414,16 +414,12 @@ impl Gamepad { /// Returns `true` if any item in the [`GamepadButton`] iterator has been pressed. pub fn any_pressed(&self, button_inputs: impl IntoIterator) -> bool { - button_inputs - .into_iter() - .any(|button_type| self.pressed(button_type)) + self.digital.any_pressed(button_inputs) } - /// Returns `true` if all items in [`GamepadButton`] have been pressed. + /// Returns `true` if all items in the [`GamepadButton`] iterator have been pressed. pub fn all_pressed(&self, button_inputs: impl IntoIterator) -> bool { - button_inputs - .into_iter() - .all(|button_type| self.pressed(button_type)) + self.digital.all_pressed(button_inputs) } /// Returns `true` if the [`GamepadButton`] has been pressed during the current frame. @@ -433,18 +429,14 @@ impl Gamepad { self.digital.just_pressed(button_type) } - /// Returns `true` if any item in [`GamepadButton`] has been pressed during the current frame. + /// Returns `true` if any item in the [`GamepadButton`] iterator has been pressed during the current frame. pub fn any_just_pressed(&self, button_inputs: impl IntoIterator) -> bool { - button_inputs - .into_iter() - .any(|button_type| self.just_pressed(button_type)) + self.digital.any_just_pressed(button_inputs) } - /// Returns `true` if all items in [`GamepadButton`] have been just pressed. + /// Returns `true` if all items in the [`GamepadButton`] iterator have been just pressed. pub fn all_just_pressed(&self, button_inputs: impl IntoIterator) -> bool { - button_inputs - .into_iter() - .all(|button_type| self.just_pressed(button_type)) + self.digital.all_just_pressed(button_inputs) } /// Returns `true` if the [`GamepadButton`] has been released during the current frame. @@ -454,24 +446,20 @@ impl Gamepad { self.digital.just_released(button_type) } - /// Returns `true` if any item in [`GamepadButton`] has just been released. + /// Returns `true` if any item in the [`GamepadButton`] iterator has just been released. pub fn any_just_released( &self, button_inputs: impl IntoIterator, ) -> bool { - button_inputs - .into_iter() - .any(|button_type| self.just_released(button_type)) + self.digital.any_just_released(button_inputs) } - /// Returns `true` if all items in [`GamepadButton`] have just been released. + /// Returns `true` if all items in the [`GamepadButton`] iterator have just been released. pub fn all_just_released( &self, button_inputs: impl IntoIterator, ) -> bool { - button_inputs - .into_iter() - .all(|button_type| self.just_released(button_type)) + self.digital.all_just_released(button_inputs) } /// Returns an iterator over all digital [button]s that are pressed. diff --git a/examples/tools/gamepad_viewer.rs b/examples/tools/gamepad_viewer.rs index 8cd95f9179..32549893c6 100644 --- a/examples/tools/gamepad_viewer.rs +++ b/examples/tools/gamepad_viewer.rs @@ -393,12 +393,12 @@ fn update_buttons( materials: Res, mut query: Query<(&mut MeshMaterial2d, &ReactTo)>, ) { - for buttons in &gamepads { + for gamepad in &gamepads { for (mut handle, react_to) in query.iter_mut() { - if buttons.just_pressed(**react_to) { + if gamepad.just_pressed(**react_to) { *handle = materials.active.clone(); } - if buttons.just_released(**react_to) { + if gamepad.just_released(**react_to) { *handle = materials.normal.clone(); } }