pub struct ButtonState<T: Eq + Hash + Copy> { /* private fields */ }Expand description
Generic button state tracker. Tracks current, just-pressed, and just-released states.
T is a key/button identifier (e.g., VirtualKey, MouseButton).
Usage: call press()/release() when events arrive, query pressed()/just_pressed()/
just_released(), then call clear_just() at end of frame.
Implementations§
Source§impl<T: Eq + Hash + Copy> ButtonState<T>
impl<T: Eq + Hash + Copy> ButtonState<T>
pub fn new() -> Self
Sourcepub fn release(&mut self, button: T)
pub fn release(&mut self, button: T)
Register a button release. Clears pressed, sets just_released.
Sourcepub fn just_pressed(&self, button: T) -> bool
pub fn just_pressed(&self, button: T) -> bool
Whether the button was pressed this frame.
Sourcepub fn just_released(&self, button: T) -> bool
pub fn just_released(&self, button: T) -> bool
Whether the button was released this frame.
Sourcepub fn clear_just(&mut self)
pub fn clear_just(&mut self)
Clear just_pressed and just_released. Call at end of frame.
Sourcepub fn get_pressed(&self) -> impl Iterator<Item = &T>
pub fn get_pressed(&self) -> impl Iterator<Item = &T>
All currently pressed buttons.
Sourcepub fn get_just_pressed(&self) -> impl Iterator<Item = &T>
pub fn get_just_pressed(&self) -> impl Iterator<Item = &T>
All buttons just pressed this frame.
Sourcepub fn get_just_released(&self) -> impl Iterator<Item = &T>
pub fn get_just_released(&self) -> impl Iterator<Item = &T>
All buttons just released this frame.
Sourcepub fn pressed_count(&self) -> usize
pub fn pressed_count(&self) -> usize
Number of currently pressed buttons.
Sourcepub fn any_pressed(&self) -> bool
pub fn any_pressed(&self) -> bool
Whether any button is pressed.
Sourcepub fn any_just_pressed(&self) -> bool
pub fn any_just_pressed(&self) -> bool
Whether any button was just pressed this frame.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ButtonState<T>
impl<T> RefUnwindSafe for ButtonState<T>where
T: RefUnwindSafe,
impl<T> Send for ButtonState<T>where
T: Send,
impl<T> Sync for ButtonState<T>where
T: Sync,
impl<T> Unpin for ButtonState<T>where
T: Unpin,
impl<T> UnsafeUnpin for ButtonState<T>
impl<T> UnwindSafe for ButtonState<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more