Skip to main content

EventBus

Struct EventBus 

Source
pub struct EventBus<S, A, Id, Ctx>
where A: Action, Id: ComponentId, Ctx: BindingContext,
{ /* private fields */ }
Expand description

Event bus that manages subscriptions and dispatches events.

Implementations§

Source§

impl<S, A, Id, Ctx> EventBus<S, A, Id, Ctx>
where S: 'static, A: Action, Id: ComponentId + 'static, Ctx: BindingContext + 'static,

Source

pub fn new() -> EventBus<S, A, Id, Ctx>

Create a new event bus.

Source

pub fn with_global_key_policy( self, policy: GlobalKeyPolicy, ) -> EventBus<S, A, Id, Ctx>

Set the global key policy.

Controls which key events are treated as “global” — global events bypass modal blocking and are delivered to global subscribers.

§Example
// Don't treat Esc as global (useful for modal-heavy apps)
let bus = EventBus::new()
    .with_global_key_policy(GlobalKeyPolicy::without_esc());
Source

pub fn register<F>(&mut self, component: Id, handler: F)
where F: for<'a, 'ctx> FnMut(RoutedEvent<'ctx, Id, Ctx>, &'a S) -> HandlerResponse<A> + 'static,

Register a handler for a component ID.

Source

pub fn register_handler<H>(&mut self, component: Id, handler: H)
where H: EventHandler<S, A, Id, Ctx> + 'static,

Register a component handler that implements EventHandler.

Source

pub fn register_global<F>(&mut self, handler: F)
where F: for<'a, 'ctx> FnMut(RoutedEvent<'ctx, Id, Ctx>, &'a S) -> HandlerResponse<A> + 'static,

Register a global handler (not tied to a component).

Source

pub fn register_global_handler<H>(&mut self, handler: H)
where H: EventHandler<S, A, Id, Ctx> + 'static,

Register a global handler that implements EventHandler.

Source

pub fn unregister( &mut self, component: Id, ) -> Option<Box<dyn for<'a, 'ctx> FnMut(RoutedEvent<'ctx, Id, Ctx>, &'a S) -> HandlerResponse<A>>>

Unregister a component handler.

Source

pub fn subscribe(&mut self, component: Id, event_type: EventType)

Subscribe a component to an event type.

Source

pub fn subscribe_many(&mut self, component: Id, event_types: &[EventType])

Subscribe a component to multiple event types.

Source

pub fn unsubscribe(&mut self, component: Id, event_type: EventType)

Unsubscribe a component from an event type.

Source

pub fn unsubscribe_all(&mut self, component: Id)

Unsubscribe a component from all event types.

Source

pub fn get_subscribers(&self, event_type: EventType) -> Vec<Id>

Get subscribers for an event type.

Source

pub fn context_mut(&mut self) -> &mut EventContext<Id>

Get mutable reference to context.

Source

pub fn context(&self) -> &EventContext<Id>

Get reference to context.

Source

pub fn handle_event( &mut self, event: &EventKind, state: &S, keybindings: &Keybindings<Ctx>, ) -> EventOutcome<A>
where S: EventRoutingState<Id, Ctx>,

Route an event through the bus and collect actions.

Routing priority: Modal → Hovered → Focused → Subscribers → Global handlers. Modal blocks non-broadcast events from reaching other components.

Trait Implementations§

Source§

impl<S, A, Id, Ctx> Default for EventBus<S, A, Id, Ctx>
where S: 'static, A: Action, Id: ComponentId + 'static, Ctx: BindingContext + 'static,

Source§

fn default() -> EventBus<S, A, Id, Ctx>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S, A, Id, Ctx> Freeze for EventBus<S, A, Id, Ctx>

§

impl<S, A, Id, Ctx> !RefUnwindSafe for EventBus<S, A, Id, Ctx>

§

impl<S, A, Id, Ctx> !Send for EventBus<S, A, Id, Ctx>

§

impl<S, A, Id, Ctx> !Sync for EventBus<S, A, Id, Ctx>

§

impl<S, A, Id, Ctx> Unpin for EventBus<S, A, Id, Ctx>
where Id: Unpin,

§

impl<S, A, Id, Ctx> !UnwindSafe for EventBus<S, A, Id, Ctx>

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more