Struct EventSubsystem
pub struct EventSubsystem { /* private fields */ }
dep_sdl3
only.Implementations§
§impl EventSubsystem
impl EventSubsystem
pub fn flush_event(&self, event_type: EventType)
pub fn flush_event(&self, event_type: EventType)
Removes all events in the event queue that match the specified event type.
pub fn flush_events(&self, min_type: u32, max_type: u32)
pub fn flush_events(&self, min_type: u32, max_type: u32)
Removes all events in the event queue that match the specified type range.
pub fn peek_events<B>(&self, max_amount: u32) -> Bwhere
B: FromIterator<Event>,
pub fn peek_events<B>(&self, max_amount: u32) -> Bwhere
B: FromIterator<Event>,
Reads the events at the front of the event queue, until the maximum amount of events is read.
The events will not be removed from the queue.
§Example
use sdl3::event::Event;
let sdl_context = sdl3::init().unwrap();
let event_subsystem = sdl_context.event().unwrap();
// Read up to 1024 events
let events: Vec<Event> = event_subsystem.peek_events(1024);
// Print each one
for event in events {
println!("{:?}", event);
}
pub unsafe fn register_event(&self) -> Result<u32, Error> ⓘ
pub unsafe fn register_event(&self) -> Result<u32, Error> ⓘ
Register a custom SDL event.
When pushing a user event, you must make sure that the type_
field is set to a
registered SDL event number.
The code
, data1
, and data2
fields can be used to store user defined data.
See the SDL documentation for more information.
§Example
let sdl = sdl3::init().unwrap();
let ev = sdl.event().unwrap();
let custom_event_type_id = unsafe { ev.register_event().unwrap() };
let event = sdl3::event::Event::User {
timestamp: 0,
window_id: 0,
type_: custom_event_type_id,
code: 456,
data1: 0x1234 as *mut libc::c_void,
data2: 0x5678 as *mut libc::c_void,
};
ev.push_event(event);
pub unsafe fn register_events(&self, nr: u32) -> Result<Vec<u32>, Error> ⓘ
pub unsafe fn register_events(&self, nr: u32) -> Result<Vec<u32>, Error> ⓘ
Registers custom SDL events.
Returns an error, if no more user events can be created.
pub fn register_custom_event<T>(&self) -> Result<(), Error> ⓘwhere
T: Any,
pub fn register_custom_event<T>(&self) -> Result<(), Error> ⓘwhere
T: Any,
pub fn push_custom_event<T>(&self, event: T) -> Result<(), Error> ⓘwhere
T: Any,
pub fn push_custom_event<T>(&self, event: T) -> Result<(), Error> ⓘwhere
T: Any,
Push a custom event
If the event type T
was not registered using
register_custom_event,
this method will panic.
§Example: pushing and receiving a custom event
struct SomeCustomEvent {
a: i32
}
let sdl = sdl3::init().unwrap();
let ev = sdl.event().unwrap();
let mut ep = sdl.event_pump().unwrap();
ev.register_custom_event::<SomeCustomEvent>().unwrap();
let event = SomeCustomEvent { a: 42 };
ev.push_custom_event(event);
let received = ep.poll_event().unwrap(); // or within a for event in ep.poll_iter()
if received.is_user_event() {
let e2 = received.as_user_event_type::<SomeCustomEvent>().unwrap();
assert_eq!(e2.a, 42);
}
pub fn event_sender(&self) -> EventSender
pub fn event_sender(&self) -> EventSender
Create an event sender that can be sent to other threads.
An EventSender
will not keep the event subsystem alive. If the event subsystem is
shut down calls to push_event
and push_custom_event
will return errors.
pub fn add_event_watch<'a, CB>(&self, callback: CB) -> EventWatch<'a, CB>where
CB: EventWatchCallback + 'a,
pub fn add_event_watch<'a, CB>(&self, callback: CB) -> EventWatch<'a, CB>where
CB: EventWatchCallback + 'a,
Create an event watcher which is called every time an event is added to event queue.
The watcher is disabled when the return value is dropped. Just calling this function without binding to a variable immediately disables the watcher. In order to make it persistent, you have to bind in a variable and keep it until it’s no longer needed.
§Example: dump every event to stderr
let sdl = sdl3::init().unwrap();
let ev = sdl.event().unwrap();
// `let _ = ...` is insufficient, as it is dropped immediately.
let _event_watch = ev.add_event_watch(|event| {
dbg!(event);
});
Trait Implementations§
§impl Clone for EventSubsystem
impl Clone for EventSubsystem
§fn clone(&self) -> EventSubsystem
fn clone(&self) -> EventSubsystem
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for EventSubsystem
impl Debug for EventSubsystem
impl Sync for EventSubsystem
Auto Trait Implementations§
impl Freeze for EventSubsystem
impl RefUnwindSafe for EventSubsystem
impl !Send for EventSubsystem
impl Unpin for EventSubsystem
impl UnwindSafe for EventSubsystem
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