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
}

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

Fields (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

impl BasicInput[src]

pub fn mouse_pressed(&self, button: MouseButton) -> bool[src]

If the mouse was pressed this last frame.

pub fn mouse_is_down(&self, button: MouseButton) -> bool[src]

If the mouse is currently down.

pub fn mouse_released(&self, button: MouseButton) -> bool[src]

If the mouse was released this last frame.

pub fn key_pressed(&self, button: VirtualKeyCode) -> bool[src]

If the key was pressed this last frame.

pub fn key_is_down(&self, button: VirtualKeyCode) -> bool[src]

If the key is currently down.

pub fn key_released(&self, button: VirtualKeyCode) -> bool[src]

If the key was released this last frame.

pub fn schedule_wakeup(&mut self, when: Instant) -> u32[src]

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.

pub fn reschedule_wakeup(&mut self, wakeup: Wakeup)[src]

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.

pub fn cancel_wakeup(&mut self, id: u32) -> Option<Wakeup>[src]

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

pub fn adjust_wakeup(&mut self, id: u32, when: Instant) -> bool[src]

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

impl Clone for BasicInput[src]

impl Debug for BasicInput[src]

impl Default for BasicInput[src]

impl PartialEq<BasicInput> for BasicInput[src]

impl StructuralPartialEq for BasicInput[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.