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: StringThe 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: CommandThe 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.
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: HelpCtxThe 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: boolWhether 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: StringThe 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: HelpCtxThe 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: boolWhether 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.
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
impl MenuItem
Sourcepub fn disabled_mut(&mut self) -> Option<&mut bool>
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§
impl Eq for MenuItem
impl StructuralPartialEq for MenuItem
Auto Trait Implementations§
impl Freeze for MenuItem
impl RefUnwindSafe for MenuItem
impl Send for MenuItem
impl Sync for MenuItem
impl Unpin for MenuItem
impl UnsafeUnpin for MenuItem
impl UnwindSafe for MenuItem
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.