Trait kas::Events

source ·
pub trait Events: Widget + Sized {
    // Provided methods
    fn make_child_id(&mut self, index: usize) -> Id { ... }
    fn configure(&mut self, cx: &mut ConfigCx<'_>) { ... }
    fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data) { ... }
    fn update(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data) { ... }
    fn update_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data) { ... }
    fn navigable(&self) -> bool { ... }
    fn handle_hover(&mut self, cx: &mut EventCx<'_>, state: bool) -> IsUsed { ... }
    fn handle_event(
        &mut self,
        cx: &mut EventCx<'_>,
        data: &Self::Data,
        event: Event
    ) -> IsUsed { ... }
    fn steal_event(
        &mut self,
        cx: &mut EventCx<'_>,
        data: &Self::Data,
        id: &Id,
        event: &Event
    ) -> IsUsed { ... }
    fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &Self::Data) { ... }
    fn handle_scroll(
        &mut self,
        cx: &mut EventCx<'_>,
        data: &Self::Data,
        scroll: Scroll
    ) { ... }
}
Expand description

Widget event-handling

This trait governs event handling as part of a Widget implementation. It is used by the #widget macro to generate hidden Widget methods.

The implementation of this method may be omitted where no event-handling is required. All methods have a default implementation.

Widget lifecycle

  1. The widget is configured (Events::configure) and immediately updated (Events::update).
  2. The widget has its size-requirements checked by calling Layout::size_rules for each axis.
  3. Layout::set_rect is called to position elements. This may use data cached by size_rules.
  4. The widget is updated again after any data change (see ConfigCx::update).
  5. The widget is ready for event-handling and drawing (Events::handle_event, Layout::find_id, Layout::draw).

Widgets are responsible for ensuring that their children may observe this lifecycle. Usually this simply involves inclusion of the child in layout operations. Steps of the lifecycle may be postponed until a widget becomes visible.

Provided Methods§

source

fn make_child_id(&mut self, index: usize) -> Id

Make an identifier for a child

This is used to assign children identifiers. It may return Id::default in order to avoid configuring the child, but in this case the widget must configure via another means.

If this is implemented explicitly then Layout::find_child_index must be too.

Default impl: self.id_ref().make_child(index)

source

fn configure(&mut self, cx: &mut ConfigCx<'_>)

Configure self

Widgets are configured before sizing, drawing and event handling (see widget lifecycle). Configuration may be repeated at any time.

Self::update is always called immediately after this method, followed by Self::configure_recurse.

The window’s scale factor (and thus any sizes available through ConfigCx::size_cx) may not be correct initially (some platforms construct all windows using scale factor 1) and/or may change in the future. Changes to the scale factor result in recalculation of Layout::size_rules but not repeated configuration.

The default implementation does nothing.

source

fn configure_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)

Configure children

This method is called after Self::configure. It usually configures all children.

The default implementation suffices except where children should not be configured (for example, to delay configuration of hidden children).

Use Events::make_child_id and ConfigCx::configure.

source

fn update(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)

Update self using input data

This method is called immediately after Self::configure and after any input data is updated, before Layout::draw is called. Typically this method is called immediately after the data is updated but the call may be delayed until when the widget becomes visible.

This method is called before Self::update_recurse.

The default implementation does nothing.

source

fn update_recurse(&mut self, cx: &mut ConfigCx<'_>, data: &Self::Data)

Update children

This method is called after Self::update. It usually configures all children. Children should be updated even if their data is () or is unchanged.

The default implementation suffices except where children should not be updated (for example, to delay update of hidden children).

Use ConfigCx::update.

source

fn navigable(&self) -> bool

Is this widget navigable via Tab key?

Note that when this method returns false the widget will not receive navigation focus via the Tab key, but it may still receive navigation focus through some other means, for example a keyboard shortcut or a mouse click.

Defaults to false. May instead be set via the navigable property of the #[widget] macro.

source

fn handle_hover(&mut self, cx: &mut EventCx<'_>, state: bool) -> IsUsed

Mouse focus handler

Called on Event::MouseHover before Self::handle_event. state is true when hovered.

When the #widget macro properties hover_highlight or cursor_icon are used, an instance of this method is generated. Otherwise, the default implementation of this method does nothing and equivalent functionality could be implemented in Events::handle_event instead.

Note: to implement hover_highlight, simply request a redraw on focus gain and loss. To implement cursor_icon, call cx.set_hover_cursor(EXPR); on focus gain.

source

fn handle_event( &mut self, cx: &mut EventCx<'_>, data: &Self::Data, event: Event ) -> IsUsed

Handle an Event

This is the primary event handler (see documentation).

This method is called on the primary event target. In this case, EventCx::last_child returns None.

This method may also be called on ancestors during unwinding (if the event remains unused and the event is reusable). In this case, EventCx::last_child returns Some(index) with the index of the child being unwound from.

Default implementation of handle_event: do nothing; return Unused.

source

fn steal_event( &mut self, cx: &mut EventCx<'_>, data: &Self::Data, id: &Id, event: &Event ) -> IsUsed

Potentially steal an event before it reaches a child

This is an optional event handler (see documentation).

The method should either return Used or return Unused without modifying cx; attempting to do otherwise (e.g. by calling EventCx::set_scroll or leaving a message on the stack when returning Unused) will result in a panic.

Default implementation: return Unused.

source

fn handle_messages(&mut self, cx: &mut EventCx<'_>, data: &Self::Data)

Handler for messages from children/descendants

This is the secondary event handler (see documentation).

It is implied that the stack contains at least one message. Use EventCx::try_pop and/or EventCx::try_observe.

EventCx::last_child may be called to find the message’s sender. This may return None (if no child was visited, which implies that the message was sent by self).

The default implementation does nothing.

source

fn handle_scroll( &mut self, cx: &mut EventCx<'_>, data: &Self::Data, scroll: Scroll )

Handler for scrolling

When, during event handling, a widget which is a strict descendant of self (i.e. not self) calls EventCx::set_scroll with a value other than Scroll::None, this method is called.

Note that Scroll::Rect values are in the child’s coordinate space, and must be translated to the widget’s own coordinate space by this method (this is not done by the default implementation since any widget with non-zero translation very likely wants to implement this method anyway).

If the child is in an independent coordinate space, then this method should call cx.set_scroll(Scroll::None) to avoid any reactions to child’s scroll requests.

EventCx::last_child may be called to find the child responsible, and should never return None (when called from this method).

The default implementation does nothing.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Events for Svg

source§

impl Events for TextEdit

source§

impl Events for AccessLabel

source§

impl Events for EventConfig

source§

impl Events for Filler

source§

impl Events for GripPart

source§

impl Events for Image

source§

impl Events for Mark

source§

impl Events for Tab

source§

impl<A> Events for MenuToggle<A>

source§

impl<A> Events for CheckBox<A>

source§

impl<A> Events for CheckButton<A>

source§

impl<A> Events for RadioBox<A>

source§

impl<A> Events for RadioButton<A>

source§

impl<A> Events for Separator<A>

source§

impl<A, D> Events for ProgressBar<A, D>
where D: Directional,

source§

impl<A, F, W> Events for FilterList<A, F, W>
where A: ListData + 'static, F: Filter<<A as SharedData>::Item, Value = String>, W: Widget<Data = UnsafeFilteredList<A>>,

source§

impl<A, F, W, G> Events for FilterBoxList<A, F, W, G>
where A: ListData + 'static, F: Filter<<A as SharedData>::Item, Value = String>, W: Widget<Data = UnsafeFilteredList<A>>, G: EditGuard<Data = ()>,

source§

impl<A, T> Events for ScrollText<A, T>
where T: Default + FormattableText + 'static,

source§

impl<A, T> Events for Spinner<A, T>
where T: SpinnerValue,

source§

impl<A, T> Events for Text<A, T>
where T: Default + FormattableText + 'static,

source§

impl<A, T, D> Events for Slider<A, T, D>
where T: SliderValue, D: Directional,

source§

impl<A, V> Events for MatrixView<A, V>
where A: MatrixData, V: Driver<<A as SharedData>::Item, A>,

source§

impl<A, V> Events for ComboBox<A, V>
where V: Clone + Debug + Eq + 'static,

source§

impl<A, V, D> Events for ListView<A, V, D>
where A: ListData, V: Driver<<A as SharedData>::Item, A>, D: Directional,

source§

impl<A, W, F> Events for Map<A, W, F>
where W: Widget, F: for<'a> Fn(&'a A) -> &'a <W as Widget>::Data,

source§

impl<A, W, S> Events for Adapt<A, W, S>
where W: Widget<Data = S>, S: Debug,

source§

impl<D> Events for ScrollBar<D>
where D: Directional,

source§

impl<Data> Events for Window<Data>
where Data: 'static,

source§

impl<Data> Events for SubMenu<Data>

source§

impl<Data, D> Events for MenuBar<Data, D>
where D: Directional,

source§

impl<G> Events for EditBox<G>
where G: EditGuard,

source§

impl<G> Events for EditField<G>
where G: EditGuard,

source§

impl<M> Events for MenuEntry<M>
where M: Clone + Debug + 'static,

source§

impl<M> Events for MarkButton<M>
where M: Clone + Debug + 'static,

source§

impl<P> Events for Canvas<P>
where P: CanvasProgram,

source§

impl<T> Events for MessageBox<T>
where T: FormattableText + 'static,

source§

impl<T> Events for Label<T>
where T: FormattableText + 'static,

source§

impl<T> Events for ScrollLabel<T>
where T: FormattableText + 'static,

source§

impl<W> Events for Popup<W>
where W: Widget,

source§

impl<W> Events for AdaptEvents<W>
where W: Widget,

source§

impl<W> Events for Button<W>
where W: Widget,

source§

impl<W> Events for Frame<W>
where W: Widget,

source§

impl<W> Events for Grid<W>
where W: Widget,

source§

impl<W> Events for NavFrame<W>
where W: Widget,

source§

impl<W> Events for ScrollBars<W>
where W: Scrollable + Widget,

source§

impl<W> Events for ScrollRegion<W>
where W: Widget,

source§

impl<W> Events for Stack<W>
where W: Widget,

source§

impl<W> Events for TabStack<W>
where W: Widget,

source§

impl<W, D> Events for WithLabel<W, D>
where W: Widget, D: Directional,

source§

impl<W, D> Events for List<W, D>
where W: Widget, D: Directional,

source§

impl<W, D> Events for Splitter<W, D>
where W: Widget, D: Directional,