pub struct Menu {
pub items: Vec<MenuItem>,
pub default: Option<usize>,
}Expand description
An ordered list of MenuItems with an optional default selection.
A Menu is the data backing a drop-down or pop-up menu: a flat list of
entries plus the index of the item that is pre-selected when the menu opens.
Use Menu::builder() to construct one fluently; the builder sets
default automatically. Construct a Menu literal only
when you need precise control over the default index — for example, when you
want to pre-select an item other than the first:
use tvision_rs::menu::{Menu, MenuItem};
use tvision_rs::command::Command;
use tvision_rs::help::HelpCtx;
// Pre-built items.
let items = vec![
MenuItem::Command {
name: "~N~ew".into(), command: Command::NEW,
key_code: None, param: None,
help_ctx: HelpCtx::NO_CONTEXT, disabled: false,
},
MenuItem::Command {
name: "~O~pen".into(), command: Command::OPEN,
key_code: None, param: None,
help_ctx: HelpCtx::NO_CONTEXT, disabled: false,
},
];
// Pre-select "Open" (index 1) rather than "New" (index 0).
let menu = Menu { items, default: Some(1) };
assert_eq!(menu.default, Some(1));Both fields are public and not invariant-checked: default may be any valid
index into items, or None. Default::default() gives an empty menu
with no pre-selection.
§Turbo Vision heritage
Ports TMenu (menus.h): the singly-linked list of items becomes a Vec
and the deflt pointer becomes an index into it.
Fields§
§items: Vec<MenuItem>The menu entries, in display order.
Iterate with .iter() / .iter_mut() or index directly. Modify in
place (e.g. to disable a specific item by index) only between menu
activations: while a MenuSession is open it holds a clone of the
menu, so changes to this vec are not visible until the next activation.
default: Option<usize>The index of the item that is highlighted when the menu first opens.
Any valid index into items, or None for no initial highlight.
MenuBuilder sets this to Some(0) for a non-empty menu and None
for an empty one. To pre-select a different item, either set this field
directly after building (menu.default = Some(n)) or construct the
struct literal. The session clones the whole Menu at open and reads
this field once as the initial highlight; subsequent navigation does not
write it back to the original, so re-activating the menu always restarts
on this index.
Implementations§
Source§impl Menu
impl Menu
Sourcepub fn builder() -> MenuBuilder
pub fn builder() -> MenuBuilder
Start building a menu with the fluent MenuBuilder.
The returned builder starts empty; chain .command(), .command_key(),
.submenu(), and .separator() calls, then finish with .build().
The first item appended automatically becomes the default selection
(default = Some(0)). Use this for the common case; if you need a
non-first default or full control over every field, construct a Menu
struct literal directly (both fields are pub).
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 UnsafeUnpin 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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.