Trait kas_widgets::menu::Menu

source ·
pub trait Menu: Widget {
    // Provided methods
    fn sub_items(&mut self) -> Option<SubItems<'_>> { ... }
    fn menu_is_open(&self) -> bool { ... }
    fn set_menu_path(
        &mut self,
        cx: &mut EventCx<'_>,
        data: &Self::Data,
        target: Option<&Id>,
        set_focus: bool
    ) { ... }
}
Expand description

Trait governing menus, sub-menus and menu-entries

Implementations will automatically receive nav focus on mouse-hover, thus should ensure that Layout::find_id returns the identifier of the widget which should be focussed, and that this widget has Events::navigable return true.

Provided Methods§

source

fn sub_items(&mut self) -> Option<SubItems<'_>>

Access row items for aligned layout

If this returns sub-items, then these items are aligned in the menu view. This involves (1) calling Self::size_rules and Self::set_rect like usual, and (2) running an external layout solver on these items (which also calls size_rules and set_rect on each item). This is redundant, but ensures the expectations on Layout::size_rules and Layout::set_rect are met.

Note further: if this returns Some(_), then spacing for menu item frames is added “magically” by the caller. The implementor should draw a frame as follows:

fn draw(&mut self, mut draw: DrawCx) {
    draw.frame(self.rect(), FrameStyle::MenuEntry, Default::default());
    // draw children here
}
source

fn menu_is_open(&self) -> bool

Report whether a submenu (if any) is open

By default, this is false.

source

fn set_menu_path( &mut self, cx: &mut EventCx<'_>, data: &Self::Data, target: Option<&Id>, set_focus: bool )

Open or close a sub-menu, including parents

Given Some(id) = target, the sub-menu with this id should open its menu; if it has child-menus, these should close; and if any ancestors are menus, these should open.

target == None implies that all menus should close.

When opening menus and set_focus is true, the first navigable child of the newly opened menu will be given focus. This is used for keyboard navigation only.

Implementations on Foreign Types§

source§

impl<T: Menu + ?Sized> Menu for Box<T>

source§

fn sub_items(&mut self) -> Option<SubItems<'_>>

source§

fn menu_is_open(&self) -> bool

source§

fn set_menu_path( &mut self, cx: &mut EventCx<'_>, data: &Self::Data, target: Option<&Id>, set_focus: bool )

Implementors§

source§

impl<A> Menu for Separator<A>

A separator is a valid menu widget

source§

impl<A> Menu for MenuToggle<A>

source§

impl<A, W: Menu<Data = ()>> Menu for MapAny<A, W>

source§

impl<Data> Menu for SubMenu<Data>

source§

impl<M: Clone + Debug + 'static> Menu for MenuEntry<M>