Skip to main content

Input

Struct Input 

Source
pub struct Input {
    pub mouse_delta: Vec2,
    pub scroll: f32,
    pub canvas: Canvas,
    /* private fields */
}
Expand description

Input snapshot, editable action bindings and shell requests.

Interior mutability permits shared script access to bindings and the HUD. Do not hold a Self::hud borrow while calling another HUD operation.

Fields§

§mouse_delta: Vec2

Pointer movement accumulated by the shell for this frame, in shell units.

§scroll: f32

Vertical wheel movement for this frame, in shell units.

§canvas: Canvas

Screen interface drawn by scripts this frame.

Implementations§

Source§

impl Input

Source

pub fn key_down(&self, k: Key) -> bool

Whether a key is held in the current snapshot.

Source

pub fn key_pressed(&self, k: Key) -> bool

True only on the frame the key went down.

Source

pub fn key_released(&self, k: Key) -> bool

True only in the snapshot where a previously held key was released.

Source

pub fn mouse_down(&self, b: MouseButton) -> bool

Whether a pointer button is currently held.

Source

pub fn mouse_pressed(&self, b: MouseButton) -> bool

True only in the snapshot where a pointer button went down.

Source

pub fn mouse_released(&self, b: MouseButton) -> bool

True only in the snapshot where a pointer button was released.

Source

pub fn lock_cursor(&self, lock: bool)

Scripts ask the shell to hide the cursor and keep it centred (mouse look).

Source

pub fn cursor_locked(&self) -> bool

Current cursor-lock request; the hosting shell is responsible for applying it.

Source

pub fn request_scene(&self, request: SceneRequest)

Asks the host to change scenes after this frame. A later request in the same frame wins.

Source

pub fn take_scene_request(&self) -> Option<SceneRequest>

Takes the pending scene change, if any (hosts call this after each tick).

Source

pub fn scene_path(&self) -> String

Asset path of the running scene (empty when the host did not say).

Source

pub fn set_scene_path(&self, path: &str)

Records the asset path of the running scene (hosts call this).

Source

pub fn set_storage(&self, storage: Storage)

Sets the game’s data folder (hosts call this once).

Source

pub fn storage(&self) -> Storage

The game’s data folder.

Source

pub fn request_quit(&self)

Asks the host to close the game.

Source

pub fn quit_requested(&self) -> bool

Whether a script asked to quit (hosts poll this).

Source

pub fn request_fullscreen(&self, on: bool)

Asks the host to switch fullscreen on or off.

Source

pub fn take_fullscreen_request(&self) -> Option<bool>

Takes a pending fullscreen request (hosts poll this).

Source

pub fn hud(&self) -> RefMut<'_, Hud>

Mutably borrows shell HUD state.

§Panics

Panics if another HUD borrow is still held.

Source

pub fn begin_frame(&self, dt: f32)

Called by the game loop every frame before scripts run.

Source

pub fn axis(&self, minus: Key, plus: Key) -> f32

Axis from two keys: +1 when plus is held, -1 when minus is held.

Source

pub fn action_down(&self, name: &str) -> bool

True while any input bound to the action is held.

Source

pub fn action_pressed(&self, name: &str) -> bool

True on the frame an input bound to the action went down.

Source

pub fn action_released(&self, name: &str) -> bool

True when the last held source of an action is released. Releasing one alternative while another is held does not release the action. A press and release of different sources in the same snapshot keeps it active.

Source

pub fn action_vector( &self, left: &str, right: &str, down: &str, up: &str, ) -> Vec2

Two-dimensional action vector, clamped to unit length to avoid faster diagonals. Positive X is right, positive Y is up; absent actions contribute zero.

Source

pub fn has_action(&self, name: &str) -> bool

Whether an action exists, including actions with no sources.

Source

pub fn remove_action(&self, name: &str) -> bool

Removes an action, returning whether it existed.

Source

pub fn try_rebind(&self, name: &str, sources: &[&str]) -> Result<(), String>

Validates all input names before replacing a binding.

Returns the first invalid name without changing existing bindings. Unlike Self::rebind, this catches configuration typos.

Source

pub fn action_axis(&self, negative: &str, positive: &str) -> f32

-1..1 from two actions, e.g. action_axis("MoveLeft", "MoveRight").

Source

pub fn rebind(&self, name: &str, sources: &[&str])

Replaces (or creates) an action’s bindings. Unknown names are ignored.

Source

pub fn bindings(&self) -> Vec<(String, Vec<&'static str>)>

Current bindings as (action, input names).

Source

pub fn set_bindings<S: AsRef<str>>(&self, defs: &[(String, Vec<S>)])

Replaces all actions. Duplicate action names use the last definition; unknown physical input names are ignored as in Self::rebind.

Source

pub fn update( &mut self, keys: HashSet<Key>, buttons: HashSet<MouseButton>, mouse_delta: Vec2, scroll: f32, )

Call once per frame with the keys/buttons that are currently held.

Source

pub fn reset(&mut self)

Clears held inputs, frame edges and pointer motion, and releases cursor lock. Bindings and HUD content are preserved. No synthetic release edges are emitted.

Trait Implementations§

Source§

impl Clone for Input

Source§

fn clone(&self) -> Input

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 Default for Input

Source§

fn default() -> Input

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

Auto Trait Implementations§

§

impl !Freeze for Input

§

impl !RefUnwindSafe for Input

§

impl !Sync for Input

§

impl Send 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> 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
§

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

§

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

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

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

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

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

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

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

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

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
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> 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> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = 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.