Struct tui_menu::MenuState

source ·
pub struct MenuState<T> { /* private fields */ }
Expand description

The state for menu, keep track of runtime info

Implementations§

create with items

Example
use tui_menu::{MenuState, MenuItem};

let state = MenuState::<&'static str>::new(vec![
    MenuItem::item("Foo", "label_foo"),
    MenuItem::group("Group", vec![
        MenuItem::item("Bar 1", "label_bar_1"),
        MenuItem::item("Bar 2", "label_bar_1"),
    ])
]);

active the menu, this will select the first item

Example
use tui_menu::{MenuState, MenuItem};

let mut state = MenuState::<&'static str>::new(vec![
    MenuItem::item("Foo", "label_foo"),
    MenuItem::group("Group", vec![
        MenuItem::item("Bar 1", "label_bar_1"),
        MenuItem::item("Bar 2", "label_bar_1"),
    ])
]);

state.activate();

assert_eq!(state.highlight().unwrap().data.unwrap(), "label_foo");

trigger up movement NOTE: this action tries to do intuitive movement, which means logicially it is not consistent, e.g: case 1: group 1 group 2 group 3 > sub item 1 sub item 2 up is pop, which closes the group 2

case 2: group 1 group 2 group 3 sub item 1 > sub item 2 up is move prev

case 3:

group 1 group 2
sub item 1 > sub item 2 > sub sub item 1 sub sub item 2

up does nothing

trigger down movement

NOTE: this action tries to do intuitive movement, which means logicially it is not consistent, e.g: case 1: group 1 > group 2 group 3 sub item 1 sub item 2 down is enter, which enter the sub group of group 2

case 2: group 1 group 2 group 3 sub item 1 > sub item 2 down does nothing

case 3: group 1 group 2
> sub item 1 sub item 2

down highlights “sub item 2”

trigger left movement

NOTE: this action tries to do intuitive movement, which means logicially it is not consistent, e.g: case 1: group 1 > group 2 group 3 sub item 1 sub item 2 left highlights “group 1”

case 2: group 1 group 2 group 3 sub item 1 > sub item 2 left first pop “sub item group”, then highlights “group 1”

case 3: group 1 group 2
> sub item 1 sub sub item 1 sub item 2 > sub sub item 2

left pop “sub sub group”

trigger right movement

NOTE: this action tries to do intuitive movement, which means logicially it is not consistent, e.g: case 1: group 1 > group 2 group 3 sub item 1 sub item 2 right highlights “group 3”

case 2: group 1 group 2 group 3 sub item 1 > sub item 2 right pop group “sub item *”, then highlights “group 3”

case 3: group 1 group 2 group 3 sub item 1 > sub item 2 + right pushes “sub sub item 2”. this differs from case 2 that current highlighted item can be expanded

select current highlight item, if it has children then push

dive into sub menu if applicable. Return: Some if entered deeper level None if nothing happen

pop the current menu group. move one layer up

clear all highlighted items. This is useful when the menu bar lose focus

client should drain events each frame, otherwise user action will feel laggy

return current highlighted item’s reference

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.