pub struct MenuState<T> { /* private fields */ }Expand description
The state for menu, keep track of runtime info
Implementations§
Source§impl<T: Clone> MenuState<T>
impl<T: Clone> MenuState<T>
Sourcepub fn new(items: Vec<MenuItem<T>>) -> Self
pub fn new(items: Vec<MenuItem<T>>) -> Self
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"),
])
]);Sourcepub fn activate(&mut self)
pub fn activate(&mut self)
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");
Sourcepub fn up(&mut self)
pub fn up(&mut self)
trigger up movement NOTE: this action tries to do intuitive movement, which means logically 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
Sourcepub fn down(&mut self)
pub fn down(&mut self)
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”
Sourcepub fn left(&mut self)
pub fn left(&mut self)
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”
Sourcepub fn right(&mut self)
pub fn right(&mut self)
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
Sourcepub fn push(&mut self) -> Option<()>
pub fn push(&mut self) -> Option<()>
dive into sub menu if applicable. Return: Some if entered deeper level None if nothing happen
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
clear all highlighted items. This is useful when the menu bar lose focus
Sourcepub fn drain_events(&mut self) -> impl Iterator<Item = MenuEvent<T>>
pub fn drain_events(&mut self) -> impl Iterator<Item = MenuEvent<T>>
client should drain events each frame, otherwise user action will feel laggy
Auto Trait Implementations§
impl<T> Freeze for MenuState<T>where
T: Freeze,
impl<T> RefUnwindSafe for MenuState<T>where
T: RefUnwindSafe,
impl<T> Send for MenuState<T>where
T: Send,
impl<T> Sync for MenuState<T>where
T: Sync,
impl<T> Unpin for MenuState<T>where
T: Unpin,
impl<T> UnwindSafe for MenuState<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more