pub struct Menu {
pub title: String,
pub items: Vec<MenuItem>,
pub enabled: bool,
pub hotkey: Option<char>,
pub focused_item: Option<usize>,
}Expand description
A menu containing a title and a collection of menu items.
Menus are displayed as dropdowns when opened and support keyboard navigation with hotkeys for quick access.
Fields§
§title: StringTitle text displayed in the menu bar
items: Vec<MenuItem>Collection of menu items in this menu
enabled: boolWhether the menu is enabled
hotkey: Option<char>Optional hotkey for quick access to this menu
focused_item: Option<usize>Index of the currently focused item when this menu is open
Implementations§
Source§impl Menu
impl Menu
Sourcepub fn with_hotkey(title: impl Into<String>, hotkey: char) -> Self
pub fn with_hotkey(title: impl Into<String>, hotkey: char) -> Self
Creates a new menu with a hotkey.
Sourcepub fn with_items<S: Into<String>>(
title: S,
hotkey: Option<char>,
items: Vec<MenuItem>,
) -> Self
pub fn with_items<S: Into<String>>( title: S, hotkey: Option<char>, items: Vec<MenuItem>, ) -> Self
Creates a new menu with title, hotkey, and items.
§Example
use tui_vision::menus::{Menu, MenuItem};
let menu = Menu::with_items("File", Some('F'), vec![
MenuItem::new_action("New", "file.new"),
MenuItem::separator(),
]);Sourcepub fn items(self, items: Vec<MenuItem>) -> Self
pub fn items(self, items: Vec<MenuItem>) -> Self
Adds multiple items to this menu (builder pattern).
Sourcepub fn add_action<S: Into<String>, C: Into<Command>>(
&mut self,
label: S,
command: C,
hotkey: Option<char>,
) -> &mut Self
pub fn add_action<S: Into<String>, C: Into<Command>>( &mut self, label: S, command: C, hotkey: Option<char>, ) -> &mut Self
Adds an action item as a convenience method.
Sourcepub fn add_separator(&mut self) -> &mut Self
pub fn add_separator(&mut self) -> &mut Self
Adds a separator as a convenience method.
Adds a submenu as a convenience method.
Source§impl Menu
impl Menu
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Sets the enabled state of the menu.
Sourcepub fn focus_next_item(&mut self)
pub fn focus_next_item(&mut self)
Focus the next selectable item.
Sourcepub fn focus_previous_item(&mut self)
pub fn focus_previous_item(&mut self)
Focus the previous selectable item.
Sourcepub fn get_focused_item(&self) -> Option<&MenuItem>
pub fn get_focused_item(&self) -> Option<&MenuItem>
Get the currently focused menu item.
Close all open submenus.
Sourcepub fn find_first_selectable_item(&self) -> Option<usize>
pub fn find_first_selectable_item(&self) -> Option<usize>
Find the first selectable (non-separator) menu item.
Sourcepub fn find_last_selectable_item(&self) -> Option<usize>
pub fn find_last_selectable_item(&self) -> Option<usize>
Find the last selectable menu item.
Sourcepub fn find_next_selectable_item(&self, current: usize) -> Option<usize>
pub fn find_next_selectable_item(&self, current: usize) -> Option<usize>
Find the next selectable menu item after the given index.
Sourcepub fn find_previous_selectable_item(&self, current: usize) -> Option<usize>
pub fn find_previous_selectable_item(&self, current: usize) -> Option<usize>
Find the previous selectable menu item before the given index.
Trait Implementations§
impl Eq for Menu
impl StructuralPartialEq for Menu
Auto Trait Implementations§
impl Freeze for Menu
impl RefUnwindSafe for Menu
impl Send for Menu
impl Sync for Menu
impl Unpin for Menu
impl UnwindSafe for Menu
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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