Enum sfml::window::Event

source ·
pub enum Event {
Show 22 variants Closed, Resized { width: u32, height: u32, }, LostFocus, GainedFocus, TextEntered { unicode: char, }, KeyPressed { code: Key, alt: bool, ctrl: bool, shift: bool, system: bool, }, KeyReleased { code: Key, alt: bool, ctrl: bool, shift: bool, system: bool, }, MouseWheelScrolled { wheel: MouseWheel, delta: f32, x: i32, y: i32, }, MouseButtonPressed { button: MouseButton, x: i32, y: i32, }, MouseButtonReleased { button: MouseButton, x: i32, y: i32, }, MouseMoved { x: i32, y: i32, }, MouseEntered, MouseLeft, JoystickButtonPressed { joystickid: u32, button: u32, }, JoystickButtonReleased { joystickid: u32, button: u32, }, JoystickMoved { joystickid: u32, axis: Axis, position: f32, }, JoystickConnected { joystickid: u32, }, JoystickDisconnected { joystickid: u32, }, TouchBegan { finger: u32, x: i32, y: i32, }, TouchMoved { finger: u32, x: i32, y: i32, }, TouchEnded { finger: u32, x: i32, y: i32, }, SensorChanged { type_: sfSensorType, x: f32, y: f32, z: f32, }, // some variants omitted
}
Expand description

Defines a system event and its parameters.

Event holds all the informations about a system event that just happened.

Events are retrieved using the Window::poll_event or Window::wait_event functions.

An Event instance contains the type of the event (mouse moved, key pressed, window closed, …) as well as the details about this particular event.

Usage example

while let Some(event) = window.poll_event() {
    match event {
        Event::Closed | Event::KeyPressed { code: Key::Escape, .. } => window.close(),
        Event::Resized { width, height } => do_something_with_the_new_size(width, height),
        _ => { /* Do nothing */ }
    }
}

Variants§

§

Closed

The window requested to be closed

§

Resized

Fields

§width: u32

The new width of the window

§height: u32

The new height of the window

The window was resized

§

LostFocus

The window lost the focus

§

GainedFocus

The window gained the focus

§

TextEntered

Fields

§unicode: char

The character entered by the user

A character was entered

§

KeyPressed

Fields

§code: Key

The pressed key

§alt: bool

Is alt pressed too?

§ctrl: bool

Is ctrl pressed too?

§shift: bool

Is shift pressed too?

§system: bool

Is system pressed too?

A key was pressed

§

KeyReleased

Fields

§code: Key

The released key

§alt: bool

Is alt released too?

§ctrl: bool

Is ctrl released too?

§shift: bool

Is shift released too?

§system: bool

Is system released too?

A key was released

§

MouseWheelScrolled

Fields

§wheel: MouseWheel

Which wheel (for mice with multiple ones).

§delta: f32

Wheel offset (positive is up/left, negative is down/right). High-precision mice may use non-integral offsets.

§x: i32

X position of the mouse pointer, relative to the left of the owner window.

§y: i32

Y position of the mouse pointer, relative to the top of the owner window.

The mouse wheel was scrolled

§

MouseButtonPressed

Fields

§button: MouseButton

Code of the button that has been pressed.

§x: i32

X position of the mouse pointer, relative to the left of the owner window.

§y: i32

Y position of the mouse pointer, relative to the top of the owner window.

A mouse button was pressed

§

MouseButtonReleased

Fields

§button: MouseButton

Code of the button that has been pressed.

§x: i32

X position of the mouse pointer, relative to the left of the owner window.

§y: i32

Y position of the mouse pointer, relative to the top of the owner window.

A mouse button was released

§

MouseMoved

Fields

§x: i32

X position of the mouse pointer, relative to the left of the owner window.

§y: i32

Y position of the mouse pointer, relative to the top of the owner window.

The mouse cursor moved

§

MouseEntered

The mouse cursor entered the area of the window

§

MouseLeft

The mouse cursor left the area of the window

§

JoystickButtonPressed

Fields

§joystickid: u32

Index of the joystick (in range [0 .. joystick::Count - 1])

§button: u32

Index of the button that has been pressed (in range [0 .. Joystick::button_count - 1])

A joystick button was pressed

§

JoystickButtonReleased

Fields

§joystickid: u32

Index of the joystick (in range [0 .. joystick::Count - 1])

§button: u32

Index of the button that has been pressed (in range [0 .. Joystick::button_count - 1])

A joystick button was released

§

JoystickMoved

Fields

§joystickid: u32

Index of the joystick (in range [0 .. joystick::Count - 1])

§axis: Axis

Axis on which the joystick moved.

§position: f32

New position on the axis (in range [-100 .. 100])

The joystick moved along an axis

§

JoystickConnected

Fields

§joystickid: u32

Index of the joystick (in range [0 .. joystick::Count - 1])

A joystick was connected

§

JoystickDisconnected

Fields

§joystickid: u32

Index of the joystick (in range [0 .. joystick::Count - 1])

A joystick was disconnected

§

TouchBegan

Fields

§finger: u32

Index of the finger in case of multi-touch events.

§x: i32

X position of the touch, relative to the left of the owner window.

§y: i32

Y position of the touch, relative to the top of the owner window.

A touch event began

§

TouchMoved

Fields

§finger: u32

Index of the finger in case of multi-touch events.

§x: i32

X position of the touch, relative to the left of the owner window.

§y: i32

Y position of the touch, relative to the top of the owner window.

A touch moved

§

TouchEnded

Fields

§finger: u32

Index of the finger in case of multi-touch events.

§x: i32

X position of the touch, relative to the left of the owner window.

§y: i32

Y position of the touch, relative to the top of the owner window.

A touch event ended

§

SensorChanged

Fields

§type_: sfSensorType

Type of the sensor.

§x: f32

Current value of the sensor on X axis.

§y: f32

Current value of the sensor on Y axis.

§z: f32

Current value of the sensor on Z axis.

A sensor value changed

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
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.