Guide API
Skip to main content

MenuItem

Enum MenuItem 

Source
pub enum MenuItem {
    Separator,
    Command {
        name: String,
        command: Command,
        key_code: Option<KeyEvent>,
        param: Option<String>,
        help_ctx: HelpCtx,
        disabled: bool,
    },
    SubMenu {
        name: String,
        key_code: Option<KeyEvent>,
        help_ctx: HelpCtx,
        disabled: bool,
        menu: Menu,
    },
}
Expand description

A single menu entry: a Separator, a Command item, or a SubMenu.

A command item carries the label, the Command it emits, and its optional accelerator key and shortcut display text. A submenu carries a label and an owned nested Menu. A separator is a divider with no other data. The command-vs-submenu split is exclusive: an entry holds either a command or a nested menu, never both.

Use MenuBuilder for the common case: .command(), .command_key(), .submenu(), and .separator() cover the usual patterns. Construct a MenuItem literal directly when you need fields the builder does not expose (e.g. a custom help_ctx or a pre-disabled item), then pass it via MenuBuilder::item.

§Turbo Vision heritage

Ports TMenuItem (menus.h), folding in its TSubMenu subclass and the newLine() separator. The implicit union { const char *param; TMenu *subMenu; } (tagged by name/command) becomes the three explicit variants (deviation D1).

Variants§

§

Separator

A horizontal divider line with no label or behaviour.

Append one with MenuBuilder::separator.

§

Command

A command item: a label that emits a Command when chosen.

When the user selects this item (via keyboard or mouse) the menu session closes and posts the command as a Event::Command broadcast. Use MenuBuilder::command for items with no accelerator, or MenuBuilder::command_key for items with an accelerator key and shortcut display text.

Fields

§name: String

The menu item label. Wrap one character in tildes (~X~) to mark it as the single-key hotkey — the menu session will highlight that character and let the user press it alone to select the item.

§command: Command

The Command broadcast when this item is chosen.

The menu session posts this as an Event::Command broadcast after closing the menu. The command must be enabled in the application’s command set for the item to be selectable; the menu session automatically greys it out (via disabled) when the command is disabled.

§key_code: Option<KeyEvent>

The global accelerator key for this item. None means no accelerator.

When set, the user can press this key combination from anywhere in the application (not just inside an open menu) to trigger the item. Use alt() to build an Alt+<char> key, or construct a KeyEvent directly for other combinations.

§param: Option<String>

Right-aligned shortcut hint shown next to the item label, e.g. "Alt-X". None means no hint is shown. Use None (or an empty string via the builder) when the item has no accelerator, or when you don’t want to advertise it in the menu.

This is display text only — the key_code field is the actual binding.

§help_ctx: HelpCtx

The help context shown when this item is highlighted.

Set to HelpCtx::NO_CONTEXT when no context-sensitive help is needed. Pass a custom value only if your application ships a help system keyed on context ids.

§disabled: bool

Whether this item is greyed out and unselectable.

For a command item this flag is framework-managed: each time the menu opens, the regray pass (update_menu_commands) overwrites it with whether command is in the program’s live disabled-command set (disabled = disabled_cmds.has(command)). Setting it at menu-build time therefore has no lasting effect for a command item — disable the command itself instead (e.g. via a Deferred command-set effect). The public MenuItem::disabled_mut accessor exists for custom graying logic; the regray pass writes the field directly rather than through it.

§

SubMenu

A submenu: a label that opens a nested Menu in a pop-up box.

When the user navigates to this item the menu session opens menu as a child menu box. Use MenuBuilder::submenu to build the nested menu with a closure; construct this variant directly only when you need to set a custom help_ctx (the builder always uses HelpCtx::NO_CONTEXT).

Fields

§name: String

The submenu label. Wrap one character in tildes (~X~) to mark the single-key hotkey, the same as for MenuItem::Command::name.

§key_code: Option<KeyEvent>

The global accelerator key for this submenu. None means no accelerator.

When set the user can press this key to open the submenu from anywhere. See MenuItem::Command::key_code and alt() for construction.

§help_ctx: HelpCtx

The help context shown while this submenu label is highlighted.

The builder always sets this to HelpCtx::NO_CONTEXT. To attach a non-default context, construct the variant directly and pass it to MenuBuilder::item.

§disabled: bool

Whether this submenu label is greyed out. Unlike MenuItem::Command::disabled, the regray pass does not manage a submenu’s own flag — set it at build time (or via disabled_mut) to grey a whole submenu.

§menu: Menu

The nested Menu opened when this item is selected.

The Menu is owned — the SubMenu variant holds the full tree, with no raw pointer or manual disposal. Build the nested menu with Menu::builder() or pass a pre-built Menu value directly.

Implementations§

Source§

impl MenuItem

Source

pub fn disabled_mut(&mut self) -> Option<&mut bool>

Returns a mutable reference to the disabled flag, or None for a Separator, which has no disabled state.

Use this for custom graying logic: call disabled_mut(), check for Some, and set the flag. Note the framework’s own regray pass (update_menu_commands) writes a command item’s flag directly from the program’s disabled-command set rather than through this accessor, so for command items prefer disabling the command itself; this handle is most useful for greying a whole submenu. Separators are never greyable so they yield None.

Trait Implementations§

Source§

impl Clone for MenuItem

Source§

fn clone(&self) -> MenuItem

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 MenuItem

Source§

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

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

impl Eq for MenuItem

Source§

impl PartialEq for MenuItem

Source§

fn eq(&self, other: &MenuItem) -> 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 MenuItem

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