Skip to main content

Event

Enum Event 

Source
pub enum Event {
Show 13 variants CloseRequested, Resized(UVec2), ScaleFactorChanged(f32), Focused(bool), Key { key: Key, pressed: bool, repeat: bool, }, Text(char), MouseMoved(Vec2), MouseButton { button: MouseButton, pressed: bool, }, MouseWheel(Vec2), GamepadConnected(GamepadId), GamepadDisconnected(GamepadId), GamepadButton { id: GamepadId, button: GamepadButton, pressed: bool, }, GamepadAxis { id: GamepadId, axis: GamepadAxis, value: f32, },
}
Expand description

Something that happened to the window or to an input device.

Events arrive in the order the operating system reported them. The window’s come from Platform::pump_events, and the gamepads’ from Platform::poll_gamepads.

Variants§

§

CloseRequested

The user asked to close the window. The window stays open: the game decides what happens next.

§

Resized(UVec2)

The inside of the window has a new size, in physical pixels.

§

ScaleFactorChanged(f32)

The scale factor is this from now on. One of these comes before any other event.

§

Focused(bool)

The window gained (true) or lost (false) the keyboard focus.

Right after Focused(false), every key and button that was down gets a release event, so nothing stays held while the window cannot see it go up. They come after it, so that a reader can tell them from the releases the user made: a UI then lets go of a held widget without taking the release for a click.

§

Key

A key went down or up.

Fields

§key: Key

Which physical key.

§pressed: bool

Down (true) or up (false).

§repeat: bool

Whether this is the keyboard repeating a key that is held down. Only a press can be a repeat.

§

Text(char)

A character the user typed, after the key press that typed it.

  • One event a character. A character composed of several key presses (a dead key and a letter, a Compose sequence, an input method’s choice on Linux and Windows) comes as one event, after the last of them. Those presses are still Event::Keys.
  • A key held down types its character again with each repeat.
  • Never a control character: Enter, Tab, Backspace, Escape and Delete come only as Event::Keys.
  • A key pressed with a shortcut’s modifier types nothing. On Linux that is Control, Alt or Super, and Alt Gr types. On Windows it is Control without Alt, which with Control is Alt Gr there, or the Windows key; Alt alone is the window menu’s. On macOS it is ⌘, or Control without Option, and Option types.
  • macOS has no input method yet: text that only an input method types (in Chinese or Japanese, say) does not come there.
§

MouseMoved(Vec2)

The pointer is here now: physical pixels from the top-left corner of the inside of the window, with y growing downward.

§

MouseButton

A mouse button went down or up.

Fields

§button: MouseButton

Which button.

§pressed: bool

Down (true) or up (false).

§

MouseWheel(Vec2)

The wheel turned, in lines. Positive y is away from the user, and positive x is to the right.

§

GamepadConnected(GamepadId)

A gamepad was plugged in, or was there when the window opened. It is at rest: what is held on it then follows as button and axis events.

§

GamepadDisconnected(GamepadId)

A gamepad was unplugged. Before this, it was put back at rest, each button held let go and each axis put back at 0 by events of their own. Its id is never given again.

§

GamepadButton

A gamepad’s button went down or up.

Fields

§id: GamepadId

Which pad.

§button: GamepadButton

Which button, by its place on the pad.

§pressed: bool

Down (true) or up (false).

§

GamepadAxis

A gamepad’s axis has a new value.

Fields

§id: GamepadId

Which pad.

§axis: GamepadAxis

Which axis.

§value: f32

-1 to 1 for a stick’s axis, with +Y down, and 0 to 1 for a trigger. Raw: no dead zone is taken off, so a stick at rest can read a little off 0.

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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 Copy for Event

Source§

impl Debug for Event

Source§

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

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

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> 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 Event

Auto Trait Implementations§

§

impl Forget for Event

§

impl Freeze for Event

§

impl Move for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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.