pub struct EventDispatcher { /* private fields */ }Expand description
Routes events through capture/bubble phases over a WidgetTree.
The dispatcher owns the handler registry but borrows the tree only immutably (to compute the ancestor path), so a caller can keep mutating the tree between dispatches.
§Allocation-free fast path
The path buffer and the deferred-edit buffer are both held as pre-allocated
Vecs that are cleared and reused across dispatches. This means that after
the first event of each size class, dispatch is completely heap-allocation-free
on the hot path (no new Vec allocations during capture/bubble traversal).
Implementations§
Source§impl EventDispatcher
impl EventDispatcher
Sourcepub fn on_capture(&mut self, id: WidgetId, handler: Box<dyn EventHandler>)
pub fn on_capture(&mut self, id: WidgetId, handler: Box<dyn EventHandler>)
Register a capture-phase handler on id.
Sourcepub fn on_bubble(&mut self, id: WidgetId, handler: Box<dyn EventHandler>)
pub fn on_bubble(&mut self, id: WidgetId, handler: Box<dyn EventHandler>)
Register a bubble-phase handler on id. Target-phase handlers are
registered here too (the target node fires its bubble handlers in the
Phase::Target step).
Sourcepub fn clear_node(&mut self, id: WidgetId) -> bool
pub fn clear_node(&mut self, id: WidgetId) -> bool
Remove every handler registered on id. Returns true if any existed.
Sourcepub fn registered_nodes(&self) -> usize
pub fn registered_nodes(&self) -> usize
Total number of nodes with at least one registered handler.
Sourcepub fn dispatch(
&mut self,
tree: &WidgetTree,
target: WidgetId,
event: DispatchEvent,
) -> Propagation
pub fn dispatch( &mut self, tree: &WidgetTree, target: WidgetId, event: DispatchEvent, ) -> Propagation
Dispatch event to target, running the capture phase (root → target),
the target phase, then the bubble phase (target → root).
Returns the merged Propagation of every handler that ran. Dispatch
stops early as soon as a handler sets stop_propagation. Registry edits
queued by handlers are applied only after this call returns.
This method is allocation-free on the hot path after the first call: it reuses pre-allocated scratch buffers for both the ancestor path and the deferred-edit queue, so no heap allocation occurs during traversal.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for EventDispatcher
impl !Send for EventDispatcher
impl !Sync for EventDispatcher
impl !UnwindSafe for EventDispatcher
impl Freeze for EventDispatcher
impl Unpin for EventDispatcher
impl UnsafeUnpin for EventDispatcher
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> 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