[−][src]Trait kas::event::SendEvent
Event routing
This trait is part of the Widget
family and is derived by
derive(Widget)
unless #[handler(send = noauto)]
or #[handler(noauto)]
is used.
This trait is responsible for routing events to the correct widget. It is
separate from Handler
since it can be derived for many parent widgets,
even when event handling must be implemented manually.
This trait is implemented by derive(Widget)
when a #[handler]
attribute
is present (except with parameter send=noauto
).
Required methods
fn send(
&mut self,
mgr: &mut Manager,
id: WidgetId,
event: Event
) -> Response<Self::Msg>
&mut self,
mgr: &mut Manager,
id: WidgetId,
event: Event
) -> Response<Self::Msg>
Send an event
This method is responsible for routing events toward descendents.
WidgetId
values are assigned via depth-first search with parents
ordered after all children. Disabling a widget is recursive, hence
disabled widgets should not forward any events.
The following logic is recommended for routing events:
if self.is_disabled() {
return Response::Unhandled(event);
}
if id <= self.child1.id() {
self.child1.event(mgr, id, event).into()
} else if id <= self.child2.id() {
self.child2.event(mgr, id, event).into()
} ... {
} else {
debug_assert!(id == self.id(), "SendEvent::send: bad WidgetId");
Manager::handle_generic(self, mgr, event)
}
Parents which don't handle any events themselves may simplify this:
if !self.is_disabled() && id <= self.w.id() {
return self.w.send(mgr, id, event);
}
Response::Unhandled(event)
When the child's Handler::Msg
type is not VoidMsg
, its response
messages can be handled here (in place of .into()
above).
The example above uses Manager::handle_generic
, which is an optional
tool able to perform some simplifications on events. It is also valid to
call Handler::handle
directly or simply to embed handling logic here.
Implementations on Foreign Types
impl<M: 'static> SendEvent for Box<dyn Widget<Msg = M>>
[src]
impl<M: 'static> SendEvent for Box<dyn Menu<Msg = M>>
[src]
Loading content...
Implementors
impl SendEvent for AccelLabel
[src]
impl SendEvent for DragHandle
[src]
impl SendEvent for Filler
[src]
impl SendEvent for Label
[src]
impl SendEvent for MessageBox
[src]
impl<D: Directional> SendEvent for ScrollBar<D>
[src]
impl<D: Directional, W: Widget> SendEvent for List<D, W>
[src]
impl<D: Directional, W: Widget> SendEvent for Splitter<D, W>
[src]
impl<D: Directional, W: Menu> SendEvent for MenuBar<D, W>
[src]
impl<D: Directional, W: Menu> SendEvent for SubMenu<D, W>
[src]
impl<G: 'static> SendEvent for EditBox<G> where
G: EditGuard,
[src]
G: EditGuard,
impl<M: 'static> SendEvent for CheckBox<M> where
M: From<VoidMsg>,
[src]
M: From<VoidMsg>,
impl<M: 'static> SendEvent for CheckBoxBare<M>
[src]
impl<M: 'static> SendEvent for MenuToggle<M> where
M: From<VoidMsg>,
[src]
M: From<VoidMsg>,
impl<M: 'static> SendEvent for RadioBox<M> where
M: From<VoidMsg>,
[src]
M: From<VoidMsg>,