[][src]Trait kas::event::SendEvent

pub trait SendEvent: Handler {
    pub fn send(
        &mut self,
        mgr: &mut Manager<'_>,
        id: WidgetId,
        event: Event
    ) -> Response<Self::Msg>; }

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

pub fn send(
    &mut self,
    mgr: &mut Manager<'_>,
    id: WidgetId,
    event: Event
) -> Response<Self::Msg>
[src]

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.

Loading content...

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 DragHandle[src]

impl SendEvent for Filler[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]

impl<M: 'static> SendEvent for CheckBox<M> where
    M: From<VoidMsg>, 
[src]

impl<M: 'static> SendEvent for CheckBoxBare<M>[src]

impl<M: 'static> SendEvent for MenuToggle<M> where
    M: From<VoidMsg>, 
[src]

impl<M: 'static> SendEvent for RadioBox<M> where
    M: From<VoidMsg>, 
[src]

impl<M: 'static> SendEvent for RadioBoxBare<M>[src]

impl<M: Clone + Debug + 'static> SendEvent for ComboBox<M>[src]

impl<M: Clone + Debug + 'static> SendEvent for MenuEntry<M>[src]

impl<M: Clone + Debug + 'static> SendEvent for TextButton<M>[src]

impl<M: Debug + 'static> SendEvent for Separator<M>[src]

impl<T: FormattableText + 'static> SendEvent for Label<T>[src]

impl<T: FormattableText + 'static> SendEvent for MessageBox<T>[src]

impl<T: SliderType, D: Directional> SendEvent for Slider<T, D>[src]

impl<W: Widget> SendEvent for Frame<W>[src]

impl<W: Widget> SendEvent for MenuFrame<W>[src]

impl<W: Widget> SendEvent for ScrollRegion<W>[src]

impl<W: Widget> SendEvent for Stack<W>[src]

impl<W: Widget<Msg = VoidMsg> + 'static> SendEvent for Window<W>[src]

Loading content...