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.

§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

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.

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§

Source§

impl Default for EventDispatcher

Source§

fn default() -> Self

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.