Enum tetra::Event[][src]

#[non_exhaustive]
pub enum Event {
Show 20 variants Resized { width: i32, height: i32, }, Restored, Minimized, Maximized, FocusGained, FocusLost, KeyPressed { key: Key, }, KeyReleased { key: Key, }, MouseButtonPressed { button: MouseButton, }, MouseButtonReleased { button: MouseButton, }, MouseMoved { position: Vec2<f32>, delta: Vec2<f32>, }, MouseWheelMoved { amount: Vec2<i32>, }, GamepadAdded { id: usize, }, GamepadRemoved { id: usize, }, GamepadButtonPressed { id: usize, button: GamepadButton, }, GamepadButtonReleased { id: usize, button: GamepadButton, }, GamepadAxisMoved { id: usize, axis: GamepadAxis, position: f32, }, GamepadStickMoved { id: usize, stick: GamepadStick, position: Vec2<f32>, }, TextInput { text: String, }, FileDropped { path: PathBuf, },
}
Expand description

Events that can occur while the game is running.

State::event will receive events as they occur.

Examples

The events example demonstrates how to handle events.

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.
Resized

The game window was resized.

Fields of Resized

width: i32

The new width of the game window.

height: i32

The new height of the game window.

Restored

The game window was restored to normal size and position by the user, either by un-minimizing or un-maximizing.

Minimized

The game window was minimized by the user.

Maximized

The game window was maximized by the user.

FocusGained

The game window was focused by the user.

FocusLost

The game window was un-focused by the user.

KeyPressed

A key on the keyboard was pressed.

Fields of KeyPressed

key: Key

The key that was pressed.

KeyReleased

A key on the keyboard was released.

Fields of KeyReleased

key: Key

The key that was released.

MouseButtonPressed

A button on the mouse was pressed.

Fields of MouseButtonPressed

button: MouseButton

The button that was pressed.

MouseButtonReleased

A button on the mouse was released.

Fields of MouseButtonReleased

button: MouseButton

The button that was released.

MouseMoved

The mouse was moved.

Fields of MouseMoved

position: Vec2<f32>

The new position of the mouse, in window co-ordinates.

If relative mouse mode is enabled, this field is not guarenteed to update.

delta: Vec2<f32>

The movement of the mouse, relative to the position of the previous MouseMoved event.

MouseWheelMoved

The mouse wheel was moved.

Fields of MouseWheelMoved

amount: Vec2<i32>

The amount that the wheel was moved.

Most ‘normal’ mice can only scroll vertically, but some devices can also scroll horizontally. Use the Y component of the returned vector if you don’t care about horizontal scroll.

Positive values correspond to scrolling up/right, negative values correspond to scrolling down/left.

GamepadAdded

A gamepad was connected to the system.

Fields of GamepadAdded

id: usize

The ID that was assigned to the gamepad.

GamepadRemoved

A gamepad was removed from the system.

Fields of GamepadRemoved

id: usize

The ID of the gamepad that was removed.

GamepadButtonPressed

A button on a gamepad was pressed.

Fields of GamepadButtonPressed

id: usize

The ID of the gamepad.

button: GamepadButton

The button that was pressed.

GamepadButtonReleased

A button on a gamepad was released.

Fields of GamepadButtonReleased

id: usize

The ID of the gamepad.

button: GamepadButton

The button that was released.

GamepadAxisMoved

An axis on a gamepad was moved.

Fields of GamepadAxisMoved

id: usize

The ID of the gamepad.

axis: GamepadAxis

The axis that was moved.

position: f32

The new position of the axis.

GamepadStickMoved

A control stick on a gamepad was moved.

Fields of GamepadStickMoved

id: usize

The ID of the gamepad.

stick: GamepadStick

The stick that was moved.

position: Vec2<f32>

The new position of the stick.

TextInput

The user typed some text.

Fields of TextInput

text: String

The text that was typed by the user.

FileDropped

The user dropped a file into the window.

This event will be fired multiple times if the user dropped multiple files at the same time.

Note that on MacOS, you must edit your info.plist file to set which document types you want your application to support, otherwise no FileDropped events will be fired.

Fields of FileDropped

path: PathBuf

The path of the file that was dropped.

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

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.