#[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
Resized
The game window was resized.
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.
KeyReleased
A key on the keyboard was released.
MouseButtonPressed
Fields
The button that was pressed.
A button on the mouse was pressed.
MouseButtonReleased
Fields
The button that was released.
A button on the mouse was released.
MouseMoved
Fields
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.
The mouse was moved.
MouseWheelMoved
Fields
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.
The mouse wheel was moved.
GamepadAdded
A gamepad was connected to the system.
GamepadRemoved
A gamepad was removed from the system.
GamepadButtonPressed
A button on a gamepad was pressed.
GamepadButtonReleased
A button on a gamepad was released.
GamepadAxisMoved
Fields
axis: GamepadAxis
The axis that was moved.
An axis on a gamepad was moved.
GamepadStickMoved
Fields
stick: GamepadStick
The stick that was moved.
A control stick on a gamepad was moved.
TextInput
The user typed some text.
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.