Guide API
Skip to main content

Menu

Struct Menu 

Source
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

Source

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§

Source§

impl Clone for Menu

Source§

fn clone(&self) -> Menu

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() -> Menu

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

impl Eq for Menu

Source§

impl PartialEq for Menu

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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> 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> CustomValue for T
where T: Any + Debug,

Source§

fn as_any_rc(self: Rc<T>) -> Rc<dyn Any>

Upcast Rc<Self> to Rc<dyn Any> so FieldValue::as_custom / FieldValue::value_as can downcast.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

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

§

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

Checks if this value is equivalent to the given key. Read more
§

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

§

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

Checks if this value is equivalent to the given key. Read more
§

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

§

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> 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.