Enum Event
pub enum Event {
Show 50 variants
Quit {
timestamp: u32,
},
AppTerminating {
timestamp: u32,
},
AppLowMemory {
timestamp: u32,
},
AppWillEnterBackground {
timestamp: u32,
},
AppDidEnterBackground {
timestamp: u32,
},
AppWillEnterForeground {
timestamp: u32,
},
AppDidEnterForeground {
timestamp: u32,
},
Display {
timestamp: u32,
display_index: i32,
display_event: DisplayEvent,
},
Window {
timestamp: u32,
window_id: u32,
win_event: WindowEvent,
},
KeyDown {
timestamp: u32,
window_id: u32,
keycode: Option<Keycode>,
scancode: Option<Scancode>,
keymod: Mod,
repeat: bool,
},
KeyUp {
timestamp: u32,
window_id: u32,
keycode: Option<Keycode>,
scancode: Option<Scancode>,
keymod: Mod,
repeat: bool,
},
TextEditing {
timestamp: u32,
window_id: u32,
text: String,
start: i32,
length: i32,
},
TextInput {
timestamp: u32,
window_id: u32,
text: String,
},
MouseMotion {
timestamp: u32,
window_id: u32,
which: u32,
mousestate: MouseState,
x: i32,
y: i32,
xrel: i32,
yrel: i32,
},
MouseButtonDown {
timestamp: u32,
window_id: u32,
which: u32,
mouse_btn: MouseButton,
clicks: u8,
x: i32,
y: i32,
},
MouseButtonUp {
timestamp: u32,
window_id: u32,
which: u32,
mouse_btn: MouseButton,
clicks: u8,
x: i32,
y: i32,
},
MouseWheel {
timestamp: u32,
window_id: u32,
which: u32,
x: i32,
y: i32,
direction: MouseWheelDirection,
precise_x: f32,
precise_y: f32,
mouse_x: i32,
mouse_y: i32,
},
JoyAxisMotion {
timestamp: u32,
which: u32,
axis_idx: u8,
value: i16,
},
JoyBallMotion {
timestamp: u32,
which: u32,
ball_idx: u8,
xrel: i16,
yrel: i16,
},
JoyHatMotion {
timestamp: u32,
which: u32,
hat_idx: u8,
state: HatState,
},
JoyButtonDown {
timestamp: u32,
which: u32,
button_idx: u8,
},
JoyButtonUp {
timestamp: u32,
which: u32,
button_idx: u8,
},
JoyDeviceAdded {
timestamp: u32,
which: u32,
},
JoyDeviceRemoved {
timestamp: u32,
which: u32,
},
ControllerAxisMotion {
timestamp: u32,
which: u32,
axis: Axis,
value: i16,
},
ControllerButtonDown {
timestamp: u32,
which: u32,
button: Button,
},
ControllerButtonUp {
timestamp: u32,
which: u32,
button: Button,
},
ControllerDeviceAdded {
timestamp: u32,
which: u32,
},
ControllerDeviceRemoved {
timestamp: u32,
which: u32,
},
ControllerDeviceRemapped {
timestamp: u32,
which: u32,
},
ControllerTouchpadDown {
timestamp: u32,
which: u32,
touchpad: u32,
finger: u32,
x: f32,
y: f32,
pressure: f32,
},
ControllerTouchpadMotion {
timestamp: u32,
which: u32,
touchpad: u32,
finger: u32,
x: f32,
y: f32,
pressure: f32,
},
ControllerTouchpadUp {
timestamp: u32,
which: u32,
touchpad: u32,
finger: u32,
x: f32,
y: f32,
pressure: f32,
},
FingerDown {
timestamp: u32,
touch_id: i64,
finger_id: i64,
x: f32,
y: f32,
dx: f32,
dy: f32,
pressure: f32,
},
FingerUp {
timestamp: u32,
touch_id: i64,
finger_id: i64,
x: f32,
y: f32,
dx: f32,
dy: f32,
pressure: f32,
},
FingerMotion {
timestamp: u32,
touch_id: i64,
finger_id: i64,
x: f32,
y: f32,
dx: f32,
dy: f32,
pressure: f32,
},
DollarGesture {
timestamp: u32,
touch_id: i64,
gesture_id: i64,
num_fingers: u32,
error: f32,
x: f32,
y: f32,
},
DollarRecord {
timestamp: u32,
touch_id: i64,
gesture_id: i64,
num_fingers: u32,
error: f32,
x: f32,
y: f32,
},
MultiGesture {
timestamp: u32,
touch_id: i64,
d_theta: f32,
d_dist: f32,
x: f32,
y: f32,
num_fingers: u16,
},
ClipboardUpdate {
timestamp: u32,
},
DropFile {
timestamp: u32,
window_id: u32,
filename: String,
},
DropText {
timestamp: u32,
window_id: u32,
filename: String,
},
DropBegin {
timestamp: u32,
window_id: u32,
},
DropComplete {
timestamp: u32,
window_id: u32,
},
AudioDeviceAdded {
timestamp: u32,
which: u32,
iscapture: bool,
},
AudioDeviceRemoved {
timestamp: u32,
which: u32,
iscapture: bool,
},
RenderTargetsReset {
timestamp: u32,
},
RenderDeviceReset {
timestamp: u32,
},
User {
timestamp: u32,
window_id: u32,
type_: u32,
code: i32,
data1: *mut c_void,
data2: *mut c_void,
},
Unknown {
timestamp: u32,
type_: u32,
},
}
dep_sdl2
only.Expand description
Different event types.
Variants§
Quit
AppTerminating
AppLowMemory
AppWillEnterBackground
AppDidEnterBackground
AppWillEnterForeground
AppDidEnterForeground
Display
Window
KeyDown
Fields
KeyUp
Fields
TextEditing
TextInput
MouseMotion
Fields
mousestate: MouseState
MouseButtonDown
MouseButtonUp
MouseWheel
Fields
direction: MouseWheelDirection
JoyAxisMotion
JoyBallMotion
JoyHatMotion
JoyButtonDown
JoyButtonUp
JoyDeviceAdded
JoyDeviceRemoved
ControllerAxisMotion
ControllerButtonDown
ControllerButtonUp
ControllerDeviceAdded
ControllerDeviceRemoved
ControllerDeviceRemapped
ControllerTouchpadDown
Fields
ControllerTouchpadMotion
Fields
ControllerTouchpadUp
Fields
FingerDown
FingerUp
FingerMotion
DollarGesture
DollarRecord
MultiGesture
ClipboardUpdate
DropFile
DropText
DropBegin
DropComplete
AudioDeviceAdded
AudioDeviceRemoved
RenderTargetsReset
RenderDeviceReset
User
Unknown
Implementations§
§impl Event
impl Event
pub fn from_ll(raw: SDL_Event) -> Event
pub fn is_user_event(&self) -> bool
pub fn as_user_event_type<T>(&self) -> Option<T> ⓘwhere
T: Any,
pub fn is_same_kind_as(&self, other: &Event) -> bool
pub fn is_same_kind_as(&self, other: &Event) -> bool
Returns true
if they are the same “kind” of events.
§Example:
use sdl2::event::Event;
let ev1 = Event::JoyButtonDown {
timestamp: 0,
which: 0,
button_idx: 0,
};
let ev2 = Event::JoyButtonDown {
timestamp: 1,
which: 1,
button_idx: 1,
};
assert!(ev1 != ev2); // The events aren't equal (they contain different values).
assert!(ev1.is_same_kind_as(&ev2)); // But they are of the same kind!
pub fn get_timestamp(&self) -> u32 ⓘ
pub fn get_timestamp(&self) -> u32 ⓘ
Returns the timestamp
field of the event.
§Example
use sdl2::event::Event;
let ev = Event::JoyButtonDown {
timestamp: 12,
which: 0,
button_idx: 0,
};
assert!(ev.get_timestamp() == 12);
pub fn get_window_id(&self) -> Option<u32> ⓘ
pub fn get_window_id(&self) -> Option<u32> ⓘ
Returns the window_id
field of the event if it’s present (not all events have it!).
§Example
use sdl2::event::Event;
let ev = Event::JoyButtonDown {
timestamp: 0,
which: 0,
button_idx: 0,
};
assert!(ev.get_window_id() == None);
let another_ev = Event::DropBegin {
timestamp: 0,
window_id: 3,
};
assert!(another_ev.get_window_id() == Some(3));
pub fn is_window(&self) -> bool
pub fn is_window(&self) -> bool
Returns true
if this is a window event.
§Example
use sdl2::event::Event;
let ev = Event::Quit {
timestamp: 0,
};
assert!(ev.is_window());
let ev = Event::AppLowMemory {
timestamp: 0,
};
assert!(ev.is_window());
let another_ev = Event::TextInput {
timestamp: 0,
window_id: 0,
text: String::new(),
};
assert!(another_ev.is_window() == false); // Not a window event!
pub fn is_keyboard(&self) -> bool
pub fn is_keyboard(&self) -> bool
Returns true
if this is a keyboard event.
§Example
use sdl2::event::Event;
use sdl2::keyboard::Mod;
let ev = Event::KeyDown {
timestamp: 0,
window_id: 0,
keycode: None,
scancode: None,
keymod: Mod::empty(),
repeat: false,
};
assert!(ev.is_keyboard());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_keyboard() == false); // Not a keyboard event!
pub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Returns true
if this is a text event.
§Example
use sdl2::event::Event;
let ev = Event::TextInput {
timestamp: 0,
window_id: 0,
text: String::new(),
};
assert!(ev.is_text());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_text() == false); // Not a text event!
pub fn is_mouse(&self) -> bool
pub fn is_mouse(&self) -> bool
Returns true
if this is a mouse event.
§Example
use sdl2::event::Event;
use sdl2::mouse::MouseWheelDirection;
let ev = Event::MouseWheel {
timestamp: 0,
window_id: 0,
which: 0,
precise_x: 0.0,
precise_y: 0.0,
x: 0,
y: 0,
mouse_x: 0,
mouse_y: 0,
direction: MouseWheelDirection::Normal,
};
assert!(ev.is_mouse());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_mouse() == false); // Not a mouse event!
pub fn is_touch(&self) -> bool
pub fn is_touch(&self) -> bool
Returns true
if this mouse event is coming from touch.
If used on any other kind of event, non-mouse related, this returns false
.
pub fn is_controller(&self) -> bool
pub fn is_controller(&self) -> bool
Returns true
if this is a controller event.
§Example
use sdl2::event::Event;
let ev = Event::ControllerDeviceAdded {
timestamp: 0,
which: 0,
};
assert!(ev.is_controller());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_controller() == false); // Not a controller event!
pub fn is_joy(&self) -> bool
pub fn is_joy(&self) -> bool
Returns true
if this is a joy event.
§Example
use sdl2::event::Event;
let ev = Event::JoyButtonUp {
timestamp: 0,
which: 0,
button_idx: 0,
};
assert!(ev.is_joy());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_joy() == false); // Not a joy event!
pub fn is_finger(&self) -> bool
pub fn is_finger(&self) -> bool
Returns true
if this is a finger event.
§Example
use sdl2::event::Event;
let ev = Event::FingerMotion {
timestamp: 0,
touch_id: 0,
finger_id: 0,
x: 0.,
y: 0.,
dx: 0.,
dy: 0.,
pressure: 0.,
};
assert!(ev.is_finger());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_finger() == false); // Not a finger event!
pub fn is_dollar(&self) -> bool
pub fn is_dollar(&self) -> bool
Returns true
if this is a dollar event.
§Example
use sdl2::event::Event;
let ev = Event::DollarGesture {
timestamp: 0,
touch_id: 0,
gesture_id: 0,
num_fingers: 0,
error: 0.,
x: 0.,
y: 0.,
};
assert!(ev.is_dollar());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_dollar() == false); // Not a dollar event!
pub fn is_drop(&self) -> bool
pub fn is_drop(&self) -> bool
Returns true
if this is a drop event.
§Example
use sdl2::event::Event;
let ev = Event::DropBegin {
timestamp: 0,
window_id: 3,
};
assert!(ev.is_drop());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_drop() == false); // Not a drop event!
pub fn is_audio(&self) -> bool
pub fn is_audio(&self) -> bool
Returns true
if this is an audio event.
§Example
use sdl2::event::Event;
let ev = Event::AudioDeviceAdded {
timestamp: 0,
which: 3,
iscapture: false,
};
assert!(ev.is_audio());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_audio() == false); // Not an audio event!
pub fn is_render(&self) -> bool
pub fn is_render(&self) -> bool
Returns true
if this is a render event.
§Example
use sdl2::event::Event;
let ev = Event::RenderTargetsReset {
timestamp: 0,
};
assert!(ev.is_render());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_render() == false); // Not a render event!
pub fn is_user(&self) -> bool
pub fn is_user(&self) -> bool
Returns true
if this is a user event.
§Example
use sdl2::event::Event;
let ev = Event::User {
timestamp: 0,
window_id: 0,
type_: 0,
code: 0,
data1: ::std::ptr::null_mut(),
data2: ::std::ptr::null_mut(),
};
assert!(ev.is_user());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_user() == false); // Not a user event!
pub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Returns true
if this is an unknown event.
§Example
use sdl2::event::Event;
let ev = Event::Unknown {
timestamp: 0,
type_: 0,
};
assert!(ev.is_unknown());
let another_ev = Event::Quit {
timestamp: 0,
};
assert!(another_ev.is_unknown() == false); // Not an unknown event!
Trait Implementations§
impl Send for Event
This does not auto-derive because User
’s data
fields can be used to
store pointers to types that are !Send
. Dereferencing these as pointers
requires using unsafe
and ensuring your own safety guarantees.
impl StructuralPartialEq for Event
impl Sync for Event
This does not auto-derive because User
’s data
fields can be used to
store pointers to types that are !Sync
. Dereferencing these as pointers
requires using unsafe
and ensuring your own safety guarantees.
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more