Enum tetra::Event

source ·
#[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

Fields

§width: i32

The new width of the game window.

§height: i32

The new height of the game window.

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

Fields

§key: Key

The key that was pressed.

A key on the keyboard was pressed.

§

KeyReleased

Fields

§key: Key

The key that was released.

A key on the keyboard was released.

§

MouseButtonPressed

Fields

§button: MouseButton

The button that was pressed.

A button on the mouse was pressed.

§

MouseButtonReleased

Fields

§button: MouseButton

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.

§delta: Vec2<f32>

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

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

Fields

§id: usize

The ID that was assigned to the gamepad.

A gamepad was connected to the system.

§

GamepadRemoved

Fields

§id: usize

The ID of the gamepad that was removed.

A gamepad was removed from the system.

§

GamepadButtonPressed

Fields

§id: usize

The ID of the gamepad.

§button: GamepadButton

The button that was pressed.

A button on a gamepad was pressed.

§

GamepadButtonReleased

Fields

§id: usize

The ID of the gamepad.

§button: GamepadButton

The button that was released.

A button on a gamepad was released.

§

GamepadAxisMoved

Fields

§id: usize

The ID of the gamepad.

§axis: GamepadAxis

The axis that was moved.

§position: f32

The new position of the axis.

An axis on a gamepad was moved.

§

GamepadStickMoved

Fields

§id: usize

The ID of the gamepad.

§stick: GamepadStick

The stick that was moved.

§position: Vec2<f32>

The new position of the stick.

A control stick on a gamepad was moved.

§

TextInput

Fields

§text: String

The text that was typed by the user.

The user typed some text.

§

FileDropped

Fields

§path: PathBuf

The path of the file that was dropped.

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.

Trait Implementations§

source§

impl Clone for Event

source§

fn clone(&self) -> Event

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Event

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

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
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,