Gamepad

Gamepad state for one sampled input snapshot.

The host samples up to four gamepads once per host-cycle input. Availability, packed button state, and axes are stored in three flat persistent lists so queries do not cross the host boundary or allocate. Button state uses the same bits as keyboard and mouse input: held is 1, pressed is 2, released is 4.

Pass input.devices directly to these helpers, and resolve a pad from the current snapshot during update! rather than keeping one. Retaining an older snapshot or View also retains its sampled lists.

from_index : U64 -> Try(Id, [InvalidGamepadIndex, ..])

Validate and wrap a zero-based gamepad index.

lookup : Snapshot, Id -> [Connected(View), Disconnected]

Resolve a slot into a snapshot-scoped connected receiver. Callers handle disconnect once, after which button and axis queries stay allocation-free.

available : { ..state, connected : List(U8) }, Id -> Bool

Compatibility query for code that only needs connectivity. Prefer snapshot.lookup(id) before reading buttons or axes.

button_up : { ..state, buttons : List(U8) }, Id, Button -> Bool

Whether a button is currently up.

button_pressed : { ..state, buttons : List(U8) }, Id, Button -> Bool

Whether a button was pressed during this input interval.

button_released : { ..state, buttons : List(U8) }, Id, Button -> Bool

Whether a button was released during this input interval.

axis : { ..state, axes : List(F32) }, Id, Axis -> F32

Read an axis from this input's latest sample. Stick axes are normally in [-1, 1]. raylib reports trigger axes in [-1, 1], where -1 is released.

Snapshot

:= {
    connected : List(U8),
    buttons : List(U8),
    axes : List(F32),
}

Fixed-size gamepad state sampled once per host-cycle input.

Id

:= [One, Two, Three, Four]

One of the four gamepad slots sampled by the platform.

is_eq : _

Compare two of these values.

Button

:= [
    Unknown,
    DpadUp,
    DpadRight,
    DpadDown,
    DpadLeft,
    FaceUp,
    FaceRight,
    FaceDown,
    FaceLeft,
    LeftBumper,
    LeftTrigger,
    RightBumper,
    RightTrigger,
    Select,
    Guide,
    Start,
    LeftStick,
    RightStick,
]

Standard gamepad buttons. Face directions are layout-neutral rather than assuming Xbox, PlayStation, or Nintendo labels.

Axis

:= [LeftX, LeftY, RightX, RightY, LeftTriggerAxis, RightTriggerAxis]

Analog stick and trigger axes.

View

Gamepad.View :: # (opaque)

A gamepad proven connected in this snapshot. This is a small value holding references to the existing flat lists; lookup does not allocate or resample. It is valid as a view of this snapshot only. Resolve the pad again from the next cycle's Devices.Snapshot instead of retaining it in the model.

id : View -> Id

Slot occupied by this connected pad.

button_up : View, Button -> Bool

Whether a button is currently up.

button_pressed : View, Button -> Bool

Whether a button was pressed during this input interval.

button_released : View, Button -> Bool

Whether a button was released during this input interval.

axis : View, Axis -> F32

Read an axis from this input's latest sample. Stick axes are normally in [-1, 1].

left_stick : View -> { x : F32, y : F32 }

Left stick as a two-dimensional vector.

right_stick : View -> { x : F32, y : F32 }

Right stick as a two-dimensional vector.