MenuBar

Struct MenuBar 

Source
pub struct MenuBar {
    pub menus: Vec<Menu>,
    pub opened_menu: Option<usize>,
    pub theme: MenuTheme,
}
Expand description

A menu bar widget that will be displayed at the top of the screen.

Only one menu can be open at a time. When a menu is opened, it displays its dropdown and becomes the active menu for keyboard navigation.

Fields§

§menus: Vec<Menu>

Collection of menus in the menu bar

§opened_menu: Option<usize>

Index of the currently opened menu (None means no menu is open)

§theme: MenuTheme

Theme configuration for rendering

Implementations§

Source§

impl MenuBar

Source

pub fn new() -> Self

Creates a new empty menu bar.

Source

pub fn from_menus<I, S>(menus: I) -> Self
where I: IntoIterator<Item = (S, Option<char>, Vec<MenuItem>)>, S: Into<String>,

Creates a new menu bar from menu definitions.

§Example
use tui_vision::menus::{MenuBar, MenuItem};

let menu_bar = MenuBar::from_menus([
    ("File", Some('F'), vec![
        MenuItem::new_action("New", "file.new"),
        MenuItem::separator(),
        MenuItem::new_action("Exit", "file.exit"),
    ]),
    ("Edit", Some('E'), vec![
        MenuItem::new_action("Undo", "edit.undo"),
        MenuItem::new_action("Redo", "edit.redo"),
    ]),
]);
Source

pub fn with_menus(menus: Vec<Menu>) -> Self

Creates a new menu bar with the given menus.

§Example
use tui_vision::menus::{MenuBar, Menu};

let menu_bar = MenuBar::with_menus(vec![
    Menu::new("File").hotkey('F'),
    Menu::new("Edit").hotkey('E'),
]);
Source

pub fn add_menu(&mut self, menu: Menu) -> &mut Self

Adds a menu to the menu bar (builder pattern).

Source

pub fn set_theme(&mut self, theme: MenuTheme) -> &mut Self

Sets the theme for the menu bar.

Source

pub fn theme(self, theme: MenuTheme) -> Self

Sets the theme for the menu bar (builder pattern).

Source

pub fn get_theme(&self) -> &MenuTheme

Gets a reference to the current theme.

Source§

impl MenuBar

Source

pub fn handle_key_event(&mut self, key: KeyEvent) -> MenuEventResult

Handles a keyboard event for the menu system.

Returns a MenuEventResult indicating what happened as a result of the key press. The caller can use this to update status messages, handle commands, etc.

Source§

impl MenuBar

Source

pub fn has_open_menu(&self) -> bool

Check if any menu is currently open.

Source

pub fn opened_menu(&self) -> Option<&Menu>

Get the currently opened menu.

Source

pub fn opened_menu_mut(&mut self) -> Option<&mut Menu>

Get the currently opened menu mutably.

Source

pub fn open_menu(&mut self, index: usize)

Open a specific menu by index.

Source

pub fn close_menu(&mut self)

Close the currently opened menu.

Source

pub fn open_next_menu(&mut self)

Open the next menu.

Source

pub fn open_previous_menu(&mut self)

Open the previous menu.

Trait Implementations§

Source§

impl Clone for MenuBar

Source§

fn clone(&self) -> MenuBar

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MenuBar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MenuBar

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for MenuBar

Source§

fn eq(&self, other: &MenuBar) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StatefulWidget for MenuBar

Stateful widget implementation for cases where you need to pass state.

Source§

type State = ()

State associated with the stateful widget. Read more
Source§

fn render(self, area: Rect, buf: &mut Buffer, _state: &mut Self::State)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom stateful widget.
Source§

impl Widget for &MenuBar

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl Widget for MenuBar

Rendering implementation for the MenuBar widget.

This implementation renders the menu bar as a horizontal strip across the top of the terminal, with menus displayed as clickable titles. When a menu is open, it displays a dropdown with the menu items.

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl Eq for MenuBar

Source§

impl StructuralPartialEq for MenuBar

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.