pub struct InputState { /* private fields */ }Expand description
Tracks the current state of all input devices (keyboard, mouse, touch) for a single game frame. The state should be updated by event handlers and cleared of per-frame data at the end of each frame.
Implementations§
Source§impl InputState
Implements input state management for InputState.
impl InputState
Implements input state management for InputState.
Sourcepub fn press_key(&mut self, key_code: String)
pub fn press_key(&mut self, key_code: String)
Records a key press event, adding to keys_pressed and keys_held.
§Arguments
String- The key code string (e.g.,"KeyA","Space").
Sourcepub fn release_key(&mut self, key_code: String)
pub fn release_key(&mut self, key_code: String)
Records a key release event, moving from keys_held to keys_released.
§Arguments
String- The key code string.
Sourcepub fn is_key_pressed<K>(&self, key_code: K) -> bool
pub fn is_key_pressed<K>(&self, key_code: K) -> bool
Sourcepub fn is_key_held<K>(&self, key_code: K) -> bool
pub fn is_key_held<K>(&self, key_code: K) -> bool
Sourcepub fn is_key_released<K>(&self, key_code: K) -> bool
pub fn is_key_released<K>(&self, key_code: K) -> bool
Records a mouse button press at the given position.
§Arguments
MouseButton- The button that was pressed.Vector2D- The mouse position.
Sourcepub fn update_mouse_position(&mut self, position: Vector2D)
pub fn update_mouse_position(&mut self, position: Vector2D)
Updates the mouse position and computes the delta from the previous position.
§Arguments
Vector2D- The new mouse position.
Sourcepub fn update_touch(&mut self, identifier: i32, position: Vector2D)
pub fn update_touch(&mut self, identifier: i32, position: Vector2D)
Adds or updates a touch point.
§Arguments
i32- The touch identifier.Vector2D- The touch position.
Sourcepub fn start_touch(&mut self, identifier: i32, position: Vector2D)
pub fn start_touch(&mut self, identifier: i32, position: Vector2D)
Records a new touch point that started this frame.
§Arguments
i32- The touch identifier.Vector2D- The touch position.
Sourcepub fn primary_touch_position(&self) -> Option<Vector2D>
pub fn primary_touch_position(&self) -> Option<Vector2D>
Returns the position of the lowest-identifier active touch point.
Pointer-style consumers (the example pages’ interactive demos) treat
the primary touch like a mouse cursor: touch events never update
mouse_position, so this accessor is the only public way to read a
touch position.
§Returns
Option<Vector2D>- The client-space position of the primary touch, orNonewhen no touch is active.
Source§impl InputState
impl InputState
pub fn get_keys_pressed(&self) -> &KeyStateSet
pub fn set_keys_pressed(&mut self, val: KeyStateSet) -> &mut Self
pub fn get_keys_held(&self) -> &KeyStateSet
pub fn set_keys_held(&mut self, val: KeyStateSet) -> &mut Self
pub fn get_keys_released(&self) -> &KeyStateSet
pub fn set_keys_released(&mut self, val: KeyStateSet) -> &mut Self
pub fn get_mouse_position(&self) -> Vector2D
pub fn set_mouse_position(&mut self, val: Vector2D) -> &mut Self
pub fn get_mouse_delta(&self) -> Vector2D
pub fn set_mouse_delta(&mut self, val: Vector2D) -> &mut Self
pub fn get_mouse_moved(&self) -> bool
pub fn set_mouse_moved(&mut self, val: bool) -> &mut Self
pub fn get_touch_points(&self) -> &TouchPointMap
pub fn set_touch_points(&mut self, val: TouchPointMap) -> &mut Self
pub fn get_touch_started(&self) -> &HashSet<i32>
pub fn set_touch_started(&mut self, val: HashSet<i32>) -> &mut Self
pub fn get_touch_ended(&self) -> &HashSet<i32>
pub fn set_touch_ended(&mut self, val: HashSet<i32>) -> &mut Self
Source§impl InputState
impl InputState
Trait Implementations§
Source§impl Clone for InputState
impl Clone for InputState
Source§fn clone(&self) -> InputState
fn clone(&self) -> InputState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InputState
impl Debug for InputState
Source§impl Default for InputState
Implements Default for InputState as a fresh empty state.
impl Default for InputState
Implements Default for InputState as a fresh empty state.