Skip to main content

Menu

Struct Menu 

Source
pub struct Menu {
    pub items: Vec<MenuItem>,
    pub default_index: Option<usize>,
}
Expand description

Menu - a collection of menu items

Matches Borland: TMenu

In Borland, TMenu has:

  • items: pointer to first item in linked list
  • deflt: pointer to default item

In Rust, we use Vec for type safety and provide convenient builders.

Fields§

§items: Vec<MenuItem>

Menu items

§default_index: Option<usize>

Index of default item (if any)

Implementations§

Source§

impl Menu

Source

pub fn new() -> Self

Create an empty menu

Matches Borland: TMenu()

Source

pub fn from_items(items: Vec<MenuItem>) -> Self

Create a menu from items

Matches Borland: TMenu(itemList)

Source

pub fn with_default(items: Vec<MenuItem>, default_index: usize) -> Self

Create a menu with a default item

Matches Borland: TMenu(itemList, deflt)

Source

pub fn add(&mut self, item: MenuItem)

Add an item to the menu

Matches Borland: appending to TMenuItem linked list

Source

pub fn find_hotkey(&self, key_code: KeyCode) -> Option<CommandId>

Find the command bound to a keyboard shortcut, searching submenus.

Matches Borland: TMenuView::findHotKey() — lets item shortcuts like F2 work while the menu is closed.

Source

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

Set the default item by index

Source

pub fn len(&self) -> usize

Get the number of items

Source

pub fn is_empty(&self) -> bool

Check if menu is empty

Trait Implementations§

Source§

impl Clone for Menu

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Menu

Source§

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

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

impl Default for Menu

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Menu

§

impl RefUnwindSafe for Menu

§

impl Send for Menu

§

impl Sync for Menu

§

impl Unpin for Menu

§

impl UnsafeUnpin for Menu

§

impl UnwindSafe for Menu

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<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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.