MenuState

Struct MenuState 

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

The state for menu, keep track of runtime info

Implementations§

Source§

impl<T: Clone> MenuState<T>

Source

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"),
    ])
]);
Source

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");
Source

pub fn is_active(&self) -> bool

Check if menu is active

Source

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

Source

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”

Source

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”

Source

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

Source

pub fn select(&mut self)

select current highlight item, if it has children then push

Source

pub fn push(&mut self) -> Option<()>

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

Source

pub fn pop(&mut self)

pop the current menu group. move one layer up

Source

pub fn reset(&mut self)

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

Source

pub fn drain_events(&mut self) -> impl Iterator<Item = MenuEvent<T>>

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

Source

pub fn highlight(&self) -> Option<&MenuItem<T>>

return current highlighted item’s reference

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.