Skip to main content

InputEvent

Enum InputEvent 

Source
#[non_exhaustive]
pub enum InputEvent { PointerMoved { position: Point, }, PointerButton { button: PointerButton, state: ElementState, position: Point, modifiers: Modifiers, }, PointerScroll { delta_x: f32, delta_y: f32, position: Point, }, PointerLeft, TouchDown { id: TouchId, position: Point, }, TouchMoved { id: TouchId, position: Point, }, TouchUp { id: TouchId, position: Point, cancelled: bool, }, Key { code: KeyCode, state: ElementState, repeat: bool, modifiers: Modifiers, }, Text { ch: char, }, SurfaceResized { size: Size, scale_factor: f32, }, CloseRequested, }
Expand description

Something the user or the windowing system did.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

PointerMoved

The pointer moved to position.

Fields

§position: Point

New position, in physical pixels.

§

PointerButton

A pointer button changed state.

Fields

§button: PointerButton

Which button.

§state: ElementState

Down or up.

§position: Point

Where it happened.

§modifiers: Modifiers

Modifiers held at the time.

§

PointerScroll

The wheel or a scroll gesture moved.

Both deltas are content offsets, not device movement: positive y scrolls content down and positive x scrolls it right, which is the sign a scroll view adds straight to its offset. A backend reporting the gesture instead — most of them do — negates both on the way in.

Saying it for one axis and not the other is how the horizontal wheel came out backwards on macOS and stayed that way: y carried this note and x carried none, so the runner negated one and passed the other through.

Fields

§delta_x: f32

Horizontal delta in physical pixels. Positive scrolls content right.

§delta_y: f32

Vertical delta in physical pixels. Positive scrolls content down.

§position: Point

Pointer position at the time.

§

PointerLeft

The pointer left the surface. Clear hover state.

§

TouchDown

A finger touched down.

Fields

§id: TouchId

Finger identity, valid until the matching InputEvent::TouchUp.

§position: Point

Contact position.

§

TouchMoved

A finger moved while down.

Fields

§id: TouchId

Finger identity.

§position: Point

New contact position.

§

TouchUp

A finger lifted, or its sequence was cancelled.

Fields

§id: TouchId

Finger identity.

§position: Point

Last known position.

§cancelled: bool

true if the system cancelled the sequence rather than the user lifting.

§

Key

A key changed state.

Fields

§code: KeyCode

Physical key position.

§state: ElementState

Down or up.

§repeat: bool

true for auto-repeat.

§modifiers: Modifiers

Modifiers held at the time.

§

Text

Committed text, one character at a time.

Emitted after dead-key composition, so pressing ¨ then o yields exactly one Text('ö') and no text for the dead key itself.

Fields

§ch: char

The character.

§

SurfaceResized

The surface changed size or DPI. Invalidate layout and damage history.

Fields

§size: Size

New extent in physical pixels.

§scale_factor: f32

New physical-per-logical pixel ratio.

§

CloseRequested

The user asked to close. The application decides whether to honour it.

Trait Implementations§

Source§

impl Clone for InputEvent

Source§

fn clone(&self) -> InputEvent

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 Debug for InputEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for InputEvent

Source§

fn eq(&self, other: &InputEvent) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for InputEvent

Auto Trait Implementations§

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
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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.