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.
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.