Skip to main content

EventDispatcher

Struct EventDispatcher 

Source
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

Source

pub fn new() -> Self

Create an empty dispatcher.

Source

pub fn on_capture(&mut self, id: WidgetId, handler: Box<dyn EventHandler>)

Register a capture-phase handler on id.

Source

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

Source

pub fn clear_node(&mut self, id: WidgetId) -> bool

Remove every handler registered on id. Returns true if any existed.

Source

pub fn registered_nodes(&self) -> usize

Total number of nodes with at least one registered handler.

Source

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.

Trait Implementations§

Source§

impl Default for EventDispatcher

Source§

fn default() -> EventDispatcher

Returns the “default value” for a 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>,

Source§

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

Source§

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.