#[repr(C)]pub struct GamepadState {
pub id: GamepadId,
pub connected: bool,
pub buttons: u32,
pub left_stick_x: f32,
pub left_stick_y: f32,
pub right_stick_x: f32,
pub right_stick_y: f32,
pub left_z: f32,
pub right_z: f32,
}Expand description
Snapshot of one gamepad’s state. Buttons are a bitset (bit n = the
GamepadButton with discriminant n); axes are explicit fields. All
POD / Copy, so it crosses the FFI by value.
Fields§
§id: GamepadIdWhich pad this snapshot is for.
connected: boolfalse once the pad disconnects (the manager keeps the last slot so
a callback can observe the disconnect).
Pressed-button bitset — bit n set ⇔ the GamepadButton with
discriminant n is held. Read via GamepadState::is_pressed.
left_stick_x: f32Left stick X in [-1, 1].
left_stick_y: f32Left stick Y in [-1, 1].
right_stick_x: f32Right stick X in [-1, 1].
right_stick_y: f32Right stick Y in [-1, 1].
left_z: f32Left trigger pressure in [0, 1].
right_z: f32Right trigger pressure in [0, 1].
Implementations§
Source§impl GamepadState
impl GamepadState
Sourcepub fn empty(id: GamepadId) -> Self
pub fn empty(id: GamepadId) -> Self
An empty (disconnected) state for id — all buttons up, axes zero.
Sourcepub fn is_pressed(&self, button: GamepadButton) -> bool
pub fn is_pressed(&self, button: GamepadButton) -> bool
Whether button is currently held.
Sourcepub fn axis(&self, axis: GamepadAxis) -> f32
pub fn axis(&self, axis: GamepadAxis) -> f32
The current value of axis (sticks [-1, 1], triggers [0, 1]).
Trait Implementations§
Source§impl Clone for GamepadState
impl Clone for GamepadState
Source§fn clone(&self) -> GamepadState
fn clone(&self) -> GamepadState
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 GamepadState
impl Debug for GamepadState
Source§impl PartialEq for GamepadState
impl PartialEq for GamepadState
Source§fn eq(&self, other: &GamepadState) -> bool
fn eq(&self, other: &GamepadState) -> bool
self and other values to be equal, and is used by ==.