[][src]Struct winit_input_helper::WinitInputHelper

pub struct WinitInputHelper { /* fields omitted */ }

The main struct of the API.

Create with WinitInputHelper::new. Call WinitInputHelper::update for every winit::event::Event you receive from winit. WinitInputHelper::update returning true indicates a step has occured. You should now run your application logic, calling any of the accessor methods you need.

An alternative API is provided via WinitInputHelper::step_with_window_events, call this method instead of WinitInputHelper::update if you need to manually control when a new step begins. A step occurs every time this method is called.

Do not mix usages of WinitInputHelper::update and WinitInputHelper::step_with_window_events. You should stick to one or the other.

Implementations

impl WinitInputHelper[src]

pub fn new() -> WinitInputHelper[src]

pub fn update<T>(&mut self, event: &Event<'_, T>) -> bool[src]

Pass every winit event to this function and run your application logic when it returns true.

The following winit events are handled:

  • Event::NewEvents clears all internal state.
  • Event::MainEventsCleared causes this function to return true, signifying a "step" has completed.
  • Event::WindowEvent updates internal state, this will affect the result of accessor methods immediately.

pub fn step_with_window_events(&mut self, events: &[WindowEvent<'_>])[src]

Pass a slice containing every winit event that occured within the step to this function. Ensure this method is only called once per application main loop. Ensure every event since the last WinitInputHelper::step_with_window_events call is included in the events argument.

WinitInputHelper::Update is easier to use. But this method is useful when your application logic steps dont line up with winit's event loop. e.g. you have a seperate thread for application logic using WinitInputHandler that constantly runs regardless of winit's event loop and you need to send events to it directly.

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

Returns true when the specified keyboard key goes from "not pressed" to "pressed" Otherwise returns false

pub fn mouse_pressed(&self, check_mouse_button: usize) -> bool[src]

Returns true when the specified mouse button goes from "not pressed" to "pressed" Otherwise returns false

Left => 0 Right => 1 Middle => 2 Other => 3..255

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

Returns true when the specified keyboard key goes from "pressed" to "not pressed" Otherwise returns false

pub fn mouse_released(&self, check_mouse_button: usize) -> bool[src]

Returns true when the specified mouse button goes from "pressed" to "not pressed" Otherwise returns false

Left => 0 Right => 1 Middle => 2 Other => 3..255

pub fn key_held(&self, key_code: VirtualKeyCode) -> bool[src]

Returns true while the specified keyboard key remains "pressed" Otherwise returns false

pub fn mouse_held(&self, mouse_button: usize) -> bool[src]

Returns true while the specified mouse button remains "pressed" Otherwise returns false

Left => 0 Right => 1 Middle => 2 Other => 3..255

pub fn held_shift(&self) -> bool[src]

Returns true while any shift key is held on the keyboard Otherwise returns false

pub fn held_control(&self) -> bool[src]

Returns true while any control key is held on the keyboard Otherwise returns false

pub fn held_alt(&self) -> bool[src]

Returns true while any alt key is held on the keyboard Otherwise returns false

pub fn scroll_diff(&self) -> f32[src]

Returns 0.0 if the mouse is outside of the window. Otherwise returns the amount scrolled by the mouse during the last step.

pub fn mouse(&self) -> Option<(f32, f32)>[src]

Returns None when the mouse is outside of the window. Otherwise returns the mouse coordinates in pixels

pub fn mouse_diff(&self) -> (f32, f32)[src]

Returns the change in mouse coordinates that occured during the last step. Returns (0.0, 0.0) if the mouse is outside of the window.

pub fn text(&self) -> Vec<TextChar>[src]

Returns the characters pressed during the last step. The earlier the character was pressed, the lower the index in the Vec.

pub fn dropped_file(&self) -> Option<PathBuf>[src]

Returns the path to a file that has been drag-and-dropped onto the window.

pub fn window_resized(&self) -> Option<PhysicalSize<u32>>[src]

Returns the current window size if it was resized during the last step. Otherwise returns None.

pub fn resolution(&self) -> Option<(u32, u32)>[src]

Returns None when no WindowEvent::Resized have been received yet. After one has been received it returns the current resolution of the window.

pub fn scale_factor_changed(&self) -> Option<f64>[src]

Returns the current scale factor if it was changed during the last step. Otherwise returns None.

pub fn scale_factor(&self) -> Option<f64>[src]

Returns None when no WindowEvent::ScaleFactorChanged have been received yet. After one has been received it returns the current scale_factor of the window.

pub fn quit(&self) -> bool[src]

Returns true if the OS has requested the application to quit. Otherwise returns false.

Trait Implementations

impl Clone for WinitInputHelper[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.