Clarify documentation regarding just_released and just_pressed inputs (#12661)

# Objective

- Clarify that `ButtonInput::just_release` and
`ButtonInput::just_pressed` don't imply information about the state of
`ButtonInput::pressed` or their counterparts.
This commit is contained in:
s-puig 2024-03-23 02:26:03 +01:00 committed by GitHub
parent 67cc605e9f
commit 037f9d414b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -143,12 +143,14 @@ where
self.just_released.extend(self.pressed.drain());
}
/// Returns `true` if the `input` has just been pressed.
/// Returns `true` if the `input` has been pressed during the current frame.
///
/// Note: This function does not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_released`].
pub fn just_pressed(&self, input: T) -> bool {
self.just_pressed.contains(&input)
}
/// Returns `true` if any item in `inputs` has just been pressed.
/// Returns `true` if any item in `inputs` has been pressed during the current frame.
pub fn any_just_pressed(&self, inputs: impl IntoIterator<Item = T>) -> bool {
inputs.into_iter().any(|it| self.just_pressed(it))
}
@ -160,7 +162,9 @@ where
self.just_pressed.remove(&input)
}
/// Returns `true` if the `input` has just been released.
/// Returns `true` if the `input` has been released during the current frame.
///
/// Note: This function does not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_pressed`].
pub fn just_released(&self, input: T) -> bool {
self.just_released.contains(&input)
}
@ -207,11 +211,15 @@ where
}
/// An iterator visiting every just pressed input in arbitrary order.
///
/// Note: Returned elements do not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_released`].
pub fn get_just_pressed(&self) -> impl ExactSizeIterator<Item = &T> {
self.just_pressed.iter()
}
/// An iterator visiting every just released input in arbitrary order.
///
/// Note: Returned elements do not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_pressed`].
pub fn get_just_released(&self) -> impl ExactSizeIterator<Item = &T> {
self.just_released.iter()
}