Skip to main content

InputState

Struct InputState 

Source
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.

Source

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").
Source

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.
Source

pub fn is_key_pressed(&self, key_code: &str) -> bool

Tests whether a key was pressed during this frame.

§Arguments
  • &str - The key code string.
§Returns
  • bool - True if the key was pressed this frame.
Source

pub fn is_key_held(&self, key_code: &str) -> bool

Tests whether a key is currently held down.

§Arguments
  • &str - The key code string.
§Returns
  • bool - True if the key is held.
Source

pub fn is_key_released(&self, key_code: &str) -> bool

Tests whether a key was released during this frame.

§Arguments
  • &str - The key code string.
§Returns
  • bool - True if the key was released this frame.
Source

pub fn press_mouse_button(&mut self, button: MouseButton, position: Vector2D)

Records a mouse button press at the given position.

§Arguments
  • MouseButton - The button that was pressed.
  • Vector2D - The mouse position.
Source

pub fn release_mouse_button(&mut self, button: MouseButton)

Records a mouse button release.

§Arguments
  • MouseButton - The button that was released.
Source

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.
Source

pub fn is_mouse_button_pressed(&self, button: MouseButton) -> bool

Tests whether a mouse button was pressed during this frame.

§Arguments
  • MouseButton - The button to check.
§Returns
  • bool - True if the button was pressed this frame.
Source

pub fn is_mouse_button_held(&self, button: MouseButton) -> bool

Tests whether a mouse button is currently held down.

§Arguments
  • MouseButton - The button to check.
§Returns
  • bool - True if the button is held.
Source

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.
Source

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.
Source

pub fn end_touch(&mut self, identifier: i32)

Removes a touch point and marks it as ended this frame.

§Arguments
  • i32 - The touch identifier.
Source

pub fn end_frame(&mut self)

Clears all per-frame input data (pressed, released, deltas).

Should be called at the end of each game frame after all input has been processed.

Source§

impl InputState

Source

pub fn get_keys_pressed(&self) -> &KeyStateSet

Source

pub fn set_keys_pressed(&mut self, val: KeyStateSet) -> &mut Self

Source

pub fn get_keys_held(&self) -> &KeyStateSet

Source

pub fn set_keys_held(&mut self, val: KeyStateSet) -> &mut Self

Source

pub fn get_keys_released(&self) -> &KeyStateSet

Source

pub fn set_keys_released(&mut self, val: KeyStateSet) -> &mut Self

Source

pub fn get_mouse_buttons_pressed(&self) -> &HashSet<MouseButton>

Source

pub fn set_mouse_buttons_pressed( &mut self, val: HashSet<MouseButton>, ) -> &mut Self

Source

pub fn get_mouse_buttons_held(&self) -> &HashSet<MouseButton>

Source

pub fn set_mouse_buttons_held(&mut self, val: HashSet<MouseButton>) -> &mut Self

Source

pub fn get_mouse_buttons_released(&self) -> &HashSet<MouseButton>

Source

pub fn set_mouse_buttons_released( &mut self, val: HashSet<MouseButton>, ) -> &mut Self

Source

pub fn get_mouse_position(&self) -> Vector2D

Source

pub fn set_mouse_position(&mut self, val: Vector2D) -> &mut Self

Source

pub fn get_mouse_delta(&self) -> Vector2D

Source

pub fn set_mouse_delta(&mut self, val: Vector2D) -> &mut Self

Source

pub fn get_mouse_moved(&self) -> bool

Source

pub fn set_mouse_moved(&mut self, val: bool) -> &mut Self

Source

pub fn get_touch_points(&self) -> &TouchPointMap

Source

pub fn set_touch_points(&mut self, val: TouchPointMap) -> &mut Self

Source

pub fn get_touch_started(&self) -> &HashSet<i32>

Source

pub fn set_touch_started(&mut self, val: HashSet<i32>) -> &mut Self

Source

pub fn get_touch_ended(&self) -> &HashSet<i32>

Source

pub fn set_touch_ended(&mut self, val: HashSet<i32>) -> &mut Self

Source§

impl InputState

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Clone for InputState

Source§

fn clone(&self) -> InputState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InputState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InputState

Implements Default for InputState as a fresh empty state.

Source§

fn default() -> InputState

Returns the “default value” for a type. Read more
Source§

impl PartialEq for InputState

Source§

fn eq(&self, other: &InputState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for InputState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more