pub struct InputState {
pub keys_pressed: HashSet<String>,
pub keys_held: HashSet<String>,
pub keys_released: HashSet<String>,
pub mouse_buttons_pressed: HashSet<MouseButton>,
pub mouse_buttons_held: HashSet<MouseButton>,
pub mouse_buttons_released: HashSet<MouseButton>,
pub mouse_position: Vector2D,
pub mouse_delta: Vector2D,
pub mouse_moved: bool,
pub touch_points: HashMap<i32, Vector2D>,
pub touch_started: HashSet<i32>,
pub touch_ended: HashSet<i32>,
}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.
Fields§
§keys_pressed: HashSet<String>Key codes that were pressed during this frame.
get_keys_pressed is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
keys_held: HashSet<String>Key codes that are currently held down.
get_keys_held is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
keys_released: HashSet<String>Key codes that were released during this frame.
get_keys_released is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
Mouse buttons that were pressed during this frame.
get_mouse_buttons_pressed is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
Mouse buttons that are currently held down.
get_mouse_buttons_held is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
Mouse buttons that were released during this frame.
get_mouse_buttons_released is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
mouse_position: Vector2DThe current mouse position in screen coordinates.
get_mouse_position is public because tests/input/fn.rs, tests/input_state/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
mouse_delta: Vector2DThe mouse position delta (movement) since the last frame.
get_mouse_delta is public because tests/input/fn.rs, tests/input_state/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
mouse_moved: boolWhether the mouse has moved during this frame.
get_mouse_moved is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
touch_points: HashMap<i32, Vector2D>Active touch points mapped by identifier to screen position.
get_touch_points is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
touch_started: HashSet<i32>Touch point identifiers that started during this frame.
get_touch_started is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
touch_ended: HashSet<i32>Touch point identifiers that ended during this frame.
get_touch_ended is public because tests/input/fn.rs reads this field from
outside this crate. get_mut / set stay crate-internal.
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) -> &HashSet<String>
pub fn get_keys_held(&self) -> &HashSet<String>
pub fn get_keys_released(&self) -> &HashSet<String>
pub fn get_mouse_position(&self) -> Vector2D
pub fn get_mouse_delta(&self) -> Vector2D
pub fn get_mouse_moved(&self) -> bool
pub fn get_touch_points(&self) -> &HashMap<i32, Vector2D>
pub fn get_touch_started(&self) -> &HashSet<i32>
pub fn get_touch_ended(&self) -> &HashSet<i32>
Source§impl InputState
impl InputState
Trait Implementations§
Source§impl Clone for InputState
impl Clone for InputState
Source§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.
Source§fn default() -> InputState
fn default() -> InputState
Constructs a default InputState value.
§Returns
InputState- A default-constructed instance with the documented initial state.