Struct sdl2::EventPump

source ·
pub struct EventPump { /* private fields */ }
Expand description

A thread-safe type that encapsulates SDL event-pumping functions.

Implementations§

source§

impl EventPump

source

pub fn is_event_enabled(&self, event_type: EventType) -> bool

Query if an event type is enabled.

source

pub fn enable_event(&mut self, event_type: EventType) -> bool

Enable an event type. Returns if the event type was enabled before the call.

source

pub fn disable_event(&mut self, event_type: EventType) -> bool

Disable an event type. Returns if the event type was enabled before the call.

source

pub fn poll_event(&mut self) -> Option<Event>

Polls for currently pending events.

If no events are pending, None is returned.

source

pub fn poll_iter(&mut self) -> EventPollIterator<'_>

Returns a polling iterator that calls poll_event(). The iterator will terminate once there are no more pending events.

Example
let sdl_context = sdl2::init().unwrap();
let mut event_pump = sdl_context.event_pump().unwrap();

for event in event_pump.poll_iter() {
    use sdl2::event::Event;
    match event {
        Event::KeyDown {..} => { /*...*/ }
        _ => ()
    }
}
source

pub fn pump_events(&mut self)

Pumps the event loop, gathering events from the input devices.

source

pub fn wait_event(&mut self) -> Event

Waits indefinitely for the next available event.

source

pub fn wait_event_timeout(&mut self, timeout: u32) -> Option<Event>

Waits until the specified timeout (in milliseconds) for the next available event.

source

pub fn wait_iter(&mut self) -> EventWaitIterator<'_>

Returns a waiting iterator that calls wait_event().

Note: The iterator will never terminate.

source

pub fn wait_timeout_iter( &mut self, timeout: u32 ) -> EventWaitTimeoutIterator<'_>

Returns a waiting iterator that calls wait_event_timeout().

Note: The iterator will never terminate, unless waiting for an event exceeds the specified timeout.

source

pub fn keyboard_state(&self) -> KeyboardState<'_>

source

pub fn mouse_state(&self) -> MouseState

source

pub fn relative_mouse_state(&self) -> RelativeMouseState

Trait Implementations§

source§

impl Drop for EventPump

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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.

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.