Struct mini_gl_fb::breakout::BasicInput[][src]

#[non_exhaustive]
pub struct BasicInput { pub mouse_pos: (f64, f64), pub mouse: HashMap<MouseButton, (bool, bool)>, pub keys: HashMap<VirtualKeyCode, (bool, bool)>, pub modifiers: ModifiersState, pub resized: bool, pub wait: bool, pub wakeups: Vec<Wakeup>, pub wakeup: Option<Wakeup>, // some fields omitted }
Expand description

Used for MiniGlFb::glutin_handle_basic_input. Contains the current state of the window in a polling-like fashion.

Fields (Non-exhaustive)

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
mouse_pos: (f64, f64)

The mouse position in buffer coordinates.

The bottom left of the window is (0, 0). Pixel centers are at multiples of (0.5, 0.5). If you want to use this to index into your buffer, in general the following is sufficient:

  • clamp each coordinate to the half-open range [0.0, buffer_size)
  • take the floor of each component
  • cast to usize and compute an index: let index = y * WIDTH + x
mouse: HashMap<MouseButton, (bool, bool)>

Stores whether a mouse button was down and is down, in that order.

If a button has not been pressed yet it will not be in the map.

keys: HashMap<VirtualKeyCode, (bool, bool)>

Stores the previous and current “key down” states, in that order.

If a key has not been pressed yet it will not be in the map.

modifiers: ModifiersState

The current modifier keys that are being pressed.

resized: bool

This is set to true when the window is resized outside of your callback. If you do not update the buffer in your callback, you should still draw it if this is true.

wait: bool

If this is set to true by your callback, it will not be called as fast as possible, but rather only when the input changes.

wakeups: Vec<Wakeup>

A record of all the Wakeups that are scheduled to happen. If your callback is being called because of a wakeup, BasicInput::wakeup will be set to Some(id) where id is the unique identifier of the Wakeup.

Wakeups can be scheduled using BasicInput::schedule_wakeup. Wakeups can be cancelled using BasicInput::cancel_wakeup, or by removing the item from the Vec.

wakeup: Option<Wakeup>

Indicates to your callback which Wakeup it should be handling. Normally, it’s okay to ignore this, as it will always be None unless you manually schedule wakeups using BasicInput::schedule_wakeup.

Implementations

If the mouse was pressed this last frame.

If the mouse is currently down.

If the mouse was released this last frame.

If the key was pressed this last frame.

If the key is currently down.

If the key was released this last frame.

Given an Instant in the future (or in the past, in which case it will be triggered immediately), schedules a wakeup to be triggered then. Returns the ID of the wakeup, which will be the ID of BasicInput::wakeup if your callback is getting called by the wakeup.

Reschedules a wakeup. It is perfectly valid to re-use IDs of wakeups that have already been triggered; that is why BasicInput::wakeup is a Wakeup and not just a u32.

Cancels a previously scheduled Wakeup by its ID. Returns the Wakeup if it is found, otherwise returns None.

Changing the time of an upcoming wakeup is common enough that there’s a utility method to do it for you. Given an ID and an Instant, finds the Wakeup with the given ID and sets its time to when. Returns true if a wakeup was found, false otherwise.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.