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: f32Cursor X position in grid units (origin at screen centre, right = +).
mouse_y: f32Cursor Y position in grid units (origin at screen centre, down = +).
left_pressed: booltrue while the left mouse button is held.
left_just_pressed: booltrue on the first frame the left mouse button goes down.
left_just_released: booltrue on the first frame the left mouse button is released.
scroll_delta: f32Lines scrolled this frame; positive = scroll down.
text_input: Vec<char>Printable characters typed this frame (from event.text, handles IME / dead keys).
backspace: booltrue if backspace was pressed this frame.
enter: booltrue if Enter/Return was pressed this frame.
escape: booltrue if Escape was pressed this frame.
tab: booltrue if Tab was pressed this frame.
arrow_left: boolArrow-left pulse this frame (fires on key-down and during auto-repeat).
arrow_right: boolArrow-right pulse this frame (fires on key-down and during auto-repeat).
arrow_up: boolArrow-up pulse this frame (fires on key-down and during auto-repeat).
arrow_down: boolArrow-down pulse this frame (fires on key-down and during auto-repeat).
shift: booltrue while Shift is held.
ctrl: booltrue while Ctrl is held.
key_a: booltrue if the ‘A’ key was pressed this frame (regardless of modifiers).
key_c: booltrue if the ‘C’ key was pressed this frame.
key_x: booltrue if the ‘X’ key was pressed this frame.
key_v: booltrue if the ‘V’ key was pressed this frame.
space: booltrue if Space or the gamepad South button was pressed this frame.
home: booltrue 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
impl Input
Sourcepub fn new_with_gilrs() -> Self
pub fn new_with_gilrs() -> Self
Like Input::new, but attempts to initialise gilrs for automatic gamepad polling.
Sourcepub fn poll_gamepad(&mut self)
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.
Sourcepub fn handle_gamepad_event(&mut self, event: Event)
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.
Sourcepub fn begin_frame(&mut self, dt: f32)
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.
Sourcepub fn keyboard_present(&self) -> bool
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.
Sourcepub fn handle_event(&mut self, event: &WindowEvent, pw: f32, ph: f32)
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().