pub struct EventBus<S, A: Action, Id: ComponentId, Ctx: BindingContext> { /* private fields */ }Expand description
Event bus that manages subscriptions and dispatches events.
Implementations§
Source§impl<S: 'static, A, Id, Ctx> EventBus<S, A, Id, Ctx>
impl<S: 'static, A, Id, Ctx> EventBus<S, A, Id, Ctx>
Sourcepub fn with_global_key_policy(self, policy: GlobalKeyPolicy) -> Self
pub fn with_global_key_policy(self, policy: GlobalKeyPolicy) -> Self
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());Sourcepub fn register<F>(&mut self, component: Id, handler: F)
pub fn register<F>(&mut self, component: Id, handler: F)
Register a handler for a component ID.
Sourcepub fn register_handler<H>(&mut self, component: Id, handler: H)where
H: EventHandler<S, A, Id, Ctx> + 'static,
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.
Sourcepub fn register_global<F>(&mut self, handler: F)
pub fn register_global<F>(&mut self, handler: F)
Register a global handler (not tied to a component).
Sourcepub fn register_global_handler<H>(&mut self, handler: H)where
H: EventHandler<S, A, Id, Ctx> + 'static,
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.
Sourcepub fn unregister(
&mut self,
component: Id,
) -> Option<Box<dyn for<'a, 'ctx> FnMut(RoutedEvent<'ctx, Id, Ctx>, &'a S) -> HandlerResponse<A>>>
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.
Sourcepub fn subscribe(&mut self, component: Id, event_type: EventType)
pub fn subscribe(&mut self, component: Id, event_type: EventType)
Subscribe a component to an event type.
Sourcepub fn subscribe_many(&mut self, component: Id, event_types: &[EventType])
pub fn subscribe_many(&mut self, component: Id, event_types: &[EventType])
Subscribe a component to multiple event types.
Sourcepub fn unsubscribe(&mut self, component: Id, event_type: EventType)
pub fn unsubscribe(&mut self, component: Id, event_type: EventType)
Unsubscribe a component from an event type.
Sourcepub fn unsubscribe_all(&mut self, component: Id)
pub fn unsubscribe_all(&mut self, component: Id)
Unsubscribe a component from all event types.
Sourcepub fn get_subscribers(&self, event_type: EventType) -> Vec<Id>
pub fn get_subscribers(&self, event_type: EventType) -> Vec<Id>
Get subscribers for an event type.
Sourcepub fn context_mut(&mut self) -> &mut EventContext<Id>
pub fn context_mut(&mut self) -> &mut EventContext<Id>
Get mutable reference to context.
Sourcepub fn context(&self) -> &EventContext<Id>
pub fn context(&self) -> &EventContext<Id>
Get reference to context.
Sourcepub fn handle_event(
&mut self,
event: &EventKind,
state: &S,
keybindings: &Keybindings<Ctx>,
) -> EventOutcome<A>where
S: EventRoutingState<Id, Ctx>,
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§
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> UnsafeUnpin for EventBus<S, A, Id, Ctx>
impl<S, A, Id, Ctx> !UnwindSafe for EventBus<S, A, Id, Ctx>
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