Add Input::reset_all
(#5015)
Adds a `reset_all` method to reset `pressed`, `just_pressed`, and `just_released` on the `Input`. Fixes #3383
This commit is contained in:
parent
9089c8b73e
commit
984ce3fa22
@ -129,7 +129,18 @@ where
|
||||
self.just_released.remove(&input);
|
||||
}
|
||||
|
||||
/// Clears the `pressed`, `just_pressed`, and `just_released` data for every input.
|
||||
///
|
||||
/// See also [`Input::clear`] for simulating elapsed time steps.
|
||||
pub fn reset_all(&mut self) {
|
||||
self.pressed.clear();
|
||||
self.just_pressed.clear();
|
||||
self.just_released.clear();
|
||||
}
|
||||
|
||||
/// Clears the `just pressed` and `just released` data for every input.
|
||||
///
|
||||
/// See also [`Input::reset_all`] for a full reset.
|
||||
pub fn clear(&mut self) {
|
||||
self.just_pressed.clear();
|
||||
self.just_released.clear();
|
||||
@ -301,6 +312,22 @@ mod test {
|
||||
assert!(!input.just_released(DummyInput::Input1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reset_all() {
|
||||
let mut input = Input::default();
|
||||
|
||||
input.press(DummyInput::Input1);
|
||||
input.press(DummyInput::Input2);
|
||||
input.release(DummyInput::Input2);
|
||||
assert!(input.pressed.contains(&DummyInput::Input1));
|
||||
assert!(input.just_pressed.contains(&DummyInput::Input1));
|
||||
assert!(input.just_released.contains(&DummyInput::Input2));
|
||||
input.reset_all();
|
||||
assert!(input.pressed.is_empty());
|
||||
assert!(input.just_pressed.is_empty());
|
||||
assert!(input.just_released.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clear() {
|
||||
let mut input = Input::default();
|
||||
|
Loading…
Reference in New Issue
Block a user