Skip to main content

GamepadState

Struct GamepadState 

Source
pub struct GamepadState { /* private fields */ }
Expand description

Per-frame and steady-state data for a single gamepad index.

The edge sets follow the same contract as InputState: buttons_pressed records a button that went down on the frame it went down and is cleared by GamepadState::end_frame, buttons_held records every button currently down and survives end_frame, and buttons_released records a button that was held and came up on this frame.

Implementations§

Source§

impl GamepadState

Implements the per-pad query surface on GamepadState.

Source

pub fn axis(&self, axis: u32) -> f64

Reads one analog axis with the deadzone applied.

§Arguments
  • u32 - The axis index to read.
§Returns
  • f64 - The deadzone-corrected reading, or 0.0 when the pad has no such axis.
Source

pub fn button_value(&self, button: u32) -> f64

Reads one button’s raw pressure without any deadzone.

§Arguments
  • u32 - The button index to read.
§Returns
  • f64 - The pressure in [0.0, 1.0], or 0.0 when the pad has no such button.
Source

pub fn is_button_pressed(&self, button: u32) -> bool

Tests whether a button went down on this frame.

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

pub fn is_button_held(&self, button: u32) -> bool

Tests whether a button is currently held down.

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

pub fn is_button_released(&self, button: u32) -> bool

Tests whether a button came up on this frame.

§Arguments
  • u32 - The button index to check.
§Returns
  • bool - True if the button was released this frame.
Source

pub fn button_action(&self, button: u32) -> InputAction

Resolves a button’s current state into the enum form.

§Arguments
  • u32 - The button index to check.
§Returns
  • InputAction - The edge state of the button, Pressed taking precedence over Released when a connect and a release land on the same frame.
Source

pub fn axis_pressed(&self, axis: u32, threshold: f64) -> bool

Tests whether a direction pair reads as a positive deflection.

§Arguments
  • u32 - The index of the axis to read.
  • f64 - The deflection that counts as a press.
§Returns
  • bool - True if the corrected axis reading reaches threshold.
Source

pub fn end_frame(&mut self)

Clears this frame’s per-frame data, keeping the held set.

Mirrors InputState::end_frame: the pressed and released sets are per-frame and are dropped, while the held set survives so a button that is still down stays held on the next frame.

Source§

impl GamepadState

Source

pub fn get_id(&self) -> String

Source

pub fn set_id(&mut self, val: String) -> &mut Self

Source

pub fn get_mut_id(&mut self) -> &mut String

Source

pub fn get_axes(&self) -> &Vec<f64>

Source

pub fn set_axes(&mut self, val: Vec<f64>) -> &mut Self

Source

pub fn get_button_values(&self) -> &Vec<f64>

Source

pub fn set_button_values(&mut self, val: Vec<f64>) -> &mut Self

Source

pub fn get_connected(&self) -> bool

Source

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

Source

pub fn get_mut_connected(&mut self) -> &mut bool

Source

pub fn get_buttons_pressed(&self) -> &GamepadButtonSet

Source

pub fn set_buttons_pressed(&mut self, val: GamepadButtonSet) -> &mut Self

Source

pub fn get_buttons_held(&self) -> &GamepadButtonSet

Source

pub fn set_buttons_held(&mut self, val: GamepadButtonSet) -> &mut Self

Source

pub fn get_buttons_released(&self) -> &GamepadButtonSet

Source

pub fn set_buttons_released(&mut self, val: GamepadButtonSet) -> &mut Self

Trait Implementations§

Source§

impl Clone for GamepadState

Source§

fn clone(&self) -> Self

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 GamepadState

Source§

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

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

impl Default for GamepadState

Source§

fn default() -> Self

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

impl PartialEq for GamepadState

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GamepadState

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 = !

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

fn try_from(value: U) -> Result<T, !>

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