pub struct EventEmitter { /* private fields */ }Expand description
Callback-based event subscription system.
Embed in MapState and call
dispatch each frame with the events drained
from InteractionManager.
Implementations§
Source§impl EventEmitter
impl EventEmitter
Sourcepub fn on<F>(&mut self, kind: InteractionEventKind, callback: F) -> ListenerId
pub fn on<F>(&mut self, kind: InteractionEventKind, callback: F) -> ListenerId
Subscribe to events of a given kind.
Returns a ListenerId that can later be passed to off.
Sourcepub fn once<F>(&mut self, kind: InteractionEventKind, callback: F) -> ListenerId
pub fn once<F>(&mut self, kind: InteractionEventKind, callback: F) -> ListenerId
Subscribe to a single occurrence of an event kind.
The listener is automatically removed after the first dispatch.
Sourcepub fn off(&mut self, id: ListenerId) -> bool
pub fn off(&mut self, id: ListenerId) -> bool
Unsubscribe a previously registered listener.
Returns true if the listener was found and removed.
Sourcepub fn dispatch(&mut self, events: &[InteractionEvent])
pub fn dispatch(&mut self, events: &[InteractionEvent])
Dispatch a batch of events to all matching listeners.
once listeners are removed after their first invocation.
Sourcepub fn listener_count(&self) -> usize
pub fn listener_count(&self) -> usize
Number of active listeners.
Sourcepub fn listener_count_for(&self, kind: InteractionEventKind) -> usize
pub fn listener_count_for(&self, kind: InteractionEventKind) -> usize
Number of listeners for a specific event kind.
Trait Implementations§
Source§impl Default for EventEmitter
impl Default for EventEmitter
impl Send for EventEmitter
impl Sync for EventEmitter
Auto Trait Implementations§
impl Freeze for EventEmitter
impl !RefUnwindSafe for EventEmitter
impl Unpin for EventEmitter
impl UnsafeUnpin for EventEmitter
impl !UnwindSafe for EventEmitter
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
Mutably borrows from an owned value. Read more