Skip to main content

Input

Struct Input 

Source
pub struct Input {
Show 25 fields pub gilrs: Option<Gilrs>, pub mouse_x: f32, pub mouse_y: f32, pub left_pressed: bool, pub left_just_pressed: bool, pub left_just_released: bool, pub scroll_delta: f32, pub text_input: Vec<char>, pub backspace: bool, pub enter: bool, pub escape: bool, pub tab: bool, pub arrow_left: bool, pub arrow_right: bool, pub arrow_up: bool, pub arrow_down: bool, pub shift: bool, pub ctrl: bool, pub key_a: bool, pub key_c: bool, pub key_x: bool, pub key_v: bool, pub space: bool, pub home: bool, pub last_hw_key: Option<Instant>, /* private fields */
}
Expand description

Raw input state in grid units (1080-unit tall coordinate space).

Updated every frame from winit events via Input::handle_event and from gilrs events via Input::poll_gamepad or Input::handle_gamepad_event. Single-frame pulse fields (left_just_pressed, arrow_left, …) are cleared by Input::begin_frame at the end of each frame.

Fields§

§gilrs: Option<Gilrs>

Optional owned gilrs instance. Present in standalone mode; None in overlay mode where the caller drives Input::handle_gamepad_event directly.

§mouse_x: f32

Cursor X position in grid units (origin at screen centre, right = +).

§mouse_y: f32

Cursor Y position in grid units (origin at screen centre, down = +).

§left_pressed: bool

true while the left mouse button is held.

§left_just_pressed: bool

true on the first frame the left mouse button goes down.

§left_just_released: bool

true on the first frame the left mouse button is released.

§scroll_delta: f32

Lines scrolled this frame; positive = scroll down.

§text_input: Vec<char>

Printable characters typed this frame (from event.text, handles IME / dead keys).

§backspace: bool

true if backspace was pressed this frame.

§enter: bool

true if Enter/Return was pressed this frame.

§escape: bool

true if Escape was pressed this frame.

§tab: bool

true if Tab was pressed this frame.

§arrow_left: bool

Arrow-left pulse this frame (fires on key-down and during auto-repeat).

§arrow_right: bool

Arrow-right pulse this frame (fires on key-down and during auto-repeat).

§arrow_up: bool

Arrow-up pulse this frame (fires on key-down and during auto-repeat).

§arrow_down: bool

Arrow-down pulse this frame (fires on key-down and during auto-repeat).

§shift: bool

true while Shift is held.

§ctrl: bool

true while Ctrl is held.

§key_a: bool

true if the ‘A’ key was pressed this frame (regardless of modifiers).

§key_c: bool

true if the ‘C’ key was pressed this frame.

§key_x: bool

true if the ‘X’ key was pressed this frame.

§key_v: bool

true if the ‘V’ key was pressed this frame.

§space: bool

true if Space or the gamepad South button was pressed this frame.

§home: bool

true if the gamepad Mode/Guide button was pressed this frame.

§last_hw_key: Option<Instant>

Timestamp of the last hardware keyboard event; used by Input::keyboard_present.

Implementations§

Source§

impl Input

Source

pub const fn new() -> Self

Create a zeroed Input with no gilrs instance.

Source

pub fn new_with_gilrs() -> Self

Like Input::new, but attempts to initialise gilrs for automatic gamepad polling.

Source

pub fn poll_gamepad(&mut self)

Poll the owned gilrs instance (if any) and map events onto input flags.

Uses take / put-back to avoid borrowing self.gilrs while dispatching to handle_gamepad_event, eliminating the per-frame Vec allocation the naive approach would require.

Source

pub fn handle_gamepad_event(&mut self, event: Event)

Feed a single gilrs event in manually.

Used in overlay mode where the caller owns the Gilrs instance and drains it themselves, or in tests.

Source

pub fn begin_frame(&mut self, dt: f32)

Clear all single-frame pulse flags and advance arrow auto-repeat timers.

Call exactly once per frame, after all widgets have read input but before the next frame’s events are collected. Note that shift and ctrl are not cleared here — they are held-modifier flags updated on key press/release, not single-frame pulses.

Source

pub fn keyboard_present(&self) -> bool

Returns true if a hardware keyboard key was pressed within the last 3 seconds.

Used to decide whether to show the on-screen keyboard: if a physical keyboard is present and recently active, suppress the OSK.

Source

pub fn handle_event(&mut self, event: &WindowEvent, pw: f32, ph: f32)

Feed a raw winit WindowEvent into the input state.

pw and ph are the current window pixel dimensions; they are needed to convert cursor pixel coordinates into the 1080-unit grid space.

Trait Implementations§

Source§

impl Default for Input

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Input

§

impl RefUnwindSafe for Input

§

impl Send for Input

§

impl !Sync for Input

§

impl Unpin for Input

§

impl UnsafeUnpin for Input

§

impl UnwindSafe for Input

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,