Trait gui::Cap

source ·
pub trait Cap {
    fn add_widget(
        &mut self,
        parent: Id,
        new_widget: &'_ mut dyn FnMut(Id, &mut dyn Cap) -> Box<dyn Widget>
    ) -> Id; fn children(&self, widget: Id) -> Iter<'_, Id>; fn root_id(&self) -> Id; fn parent_id(&self, widget: Id) -> Option<Id>; fn show(&mut self, widget: Id); fn hide(&mut self, widget: Id); fn is_visible(&self, widget: Id) -> bool; fn is_displayed(&self, widget: Id) -> bool; fn focused(&self) -> Option<Id>; fn focus(&mut self, widget: Id); fn is_focused(&self, widget: Id) -> bool; fn hook_events(
        &mut self,
        widget: Id,
        hook_fn: Option<&'static dyn Fn(&mut dyn Widget, Event, &dyn Cap) -> Option<UiEvents>>
    ) -> Option<&'static dyn Fn(&mut dyn Widget, Event, &dyn Cap) -> Option<UiEvents>>; }
Expand description

A capability allowing for various widget related operations.

Required Methods

Add a widget to the Ui represented by the capability.

Retrieve an iterator over the children. Iteration happens in z-order, from highest to lowest.

Retrieve the Id of the root widget.

Retrieve the parent of the given widget.

Show a widget, i.e., set its and its parents’ visibility flag.

This method sets the referenced widget’s visibility flag as well as those of all its parents.

Hide a widget, i.e., unset its visibility flag.

This method makes sure that widget referenced is no longer displayed. If the widget has children, all those children will also be hidden.

Check whether a widget has its visibility flag set.

Note that a return value of true does not necessary mean that the widget is actually visible. A widget is only visible if all its parents have the visibility flag set, too. The is_displayed method can be used to check for actual visibility.

Check whether a widget is actually being displayed.

This method checks whether the referenced widget is actually being displayed, that is, whether its own as well as its parents’ visibility flags are all set.

Retrieve the currently focused widget.

Focus a widget.

The focused widget is the one receiving certain types of events (such as key events) first but may also be rendered in a different color or be otherwise highlighted. Note that being focused implies being visible. This invariant is enforced internally.

Check whether the widget with the given Id is focused.

Install or remove an event hook handler.

The event hook handler is a call back function that is invoked for all events originating outside of the UI, i.e., those that come in through the Ui::handle method. For such events, the event hook handler gets to inspect the event before any widget gets a chance to handle it “officially” through the Handleable::handle method.

Event hook handlers are allowed to emit events on its own, just as “normal” event handlers. It is guaranteed that these emitted events will reach the widget after the event that was hooked.

Note that event hook functions are only able to inspect events and not change or discard them. That restriction prevents conflicts due to what effectively comes down to shared global state: widgets could be racing to install an event hook handler and the order in which these handlers end up being installed could influence the handling of events.

A widget (identified by the given Id) may only register one handler and subsequent requests will overwrite the previously installed one. The method returns the handler that was previously installed, if any.

Implementors