Struct sdl2::event::EventSender [−][src]
pub struct EventSender { /* fields omitted */ }Expand description
A sendible type that can push events to the event queue.
Implementations
Pushes an event to the event queue.
Push a custom event
If the event type T was not registered using
[EventSubsystem::register_custom_event]
(../struct.EventSubsystem.html#method.register_custom_event),
this method will panic.
Example: pushing and receiving a custom event
struct SomeCustomEvent {
a: i32
}
let sdl = sdl2::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);
}