pub struct MenuItemSpec {
pub id: MenuItemId,
pub label: String,
pub shortcut: Option<String>,
pub icon: Option<IconRole>,
pub enabled: bool,
pub visible: bool,
pub checkable: bool,
pub checked: bool,
pub submenu: Option<MenuId>,
}Expand description
In-memory specification and descriptor of one menu item.
Models native or simulated menu items across platforms: unique MenuItemId,
visible label text (with access-key mnemonics), optional keyboard accelerator
shortcut (e.g. "Ctrl+N"), optional stock-art icon (IconRole), enabled/checked
states, and visibility.
Fields§
§id: MenuItemIdStable application-facing item identifier.
label: StringVisible text/label (also carries mnemonic access-key markers such as &File).
shortcut: Option<String>Optional keyboard accelerator shortcut string (e.g. "Ctrl+N").
icon: Option<IconRole>Optional stock-art icon role resolved by the art provider.
enabled: boolWhether the menu item can be activated.
visible: boolWhether the menu item is visible.
checkable: boolWhether the menu item supports a checked/toggle state.
checked: boolCurrent checked state for checkable items.
Optional submenu identifier attached to this item.
Implementations§
Source§impl MenuItemSpec
impl MenuItemSpec
Sourcepub fn new(id: MenuItemId, label: impl Into<String>) -> Self
pub fn new(id: MenuItemId, label: impl Into<String>) -> Self
Creates an enabled, visible, plain menu item specification.
Sourcepub fn unassigned(label: impl Into<String>) -> Self
pub fn unassigned(label: impl Into<String>) -> Self
Creates an unassigned menu item specification with a placeholder ID (0).
Sourcepub fn with_shortcut(self, shortcut: impl Into<String>) -> Self
pub fn with_shortcut(self, shortcut: impl Into<String>) -> Self
Sets the keyboard shortcut hint (e.g. "Ctrl+N").
Sourcepub fn with_optional_icon(self, icon: Option<IconRole>) -> Self
pub fn with_optional_icon(self, icon: Option<IconRole>) -> Self
Sets or clears the stock-art icon role with an optional value.
Sourcepub fn with_icon_identifier(self, identifier: &str) -> Self
pub fn with_icon_identifier(self, identifier: &str) -> Self
Sets the stock-art icon role from its stable identifier (e.g. "new", "open").
Sourcepub fn with_enabled(self, enabled: bool) -> Self
pub fn with_enabled(self, enabled: bool) -> Self
Sets the enabled state.
Sourcepub fn with_visible(self, visible: bool) -> Self
pub fn with_visible(self, visible: bool) -> Self
Sets the visibility state.
Sourcepub fn with_checkable(self) -> Self
pub fn with_checkable(self) -> Self
Marks the menu item as checkable.
Sourcepub fn with_checked(self, checked: bool) -> Self
pub fn with_checked(self, checked: bool) -> Self
Sets the checked state (and marks the item as checkable).
Sets the attached submenu id.
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Sets the visible label.
Sourcepub fn with_text(self, text: impl Into<String>) -> Self
pub fn with_text(self, text: impl Into<String>) -> Self
Sets the visible text (alias for Self::with_label).
Sourcepub const fn id(&self) -> MenuItemId
pub const fn id(&self) -> MenuItemId
Returns the item’s identifier.
Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Returns the item’s text (alias for Self::label).
Sourcepub fn set_text(&mut self, text: impl Into<String>)
pub fn set_text(&mut self, text: impl Into<String>)
Sets the item’s visible text (alias for Self::set_label).
Sourcepub fn set_shortcut(&mut self, shortcut: Option<String>)
pub fn set_shortcut(&mut self, shortcut: Option<String>)
Sets the optional keyboard shortcut.
Sourcepub fn icon_identifier(&self) -> Option<&'static str>
pub fn icon_identifier(&self) -> Option<&'static str>
Returns the stable string identifier of the icon, if one is set.
Sourcepub const fn has_icon(&self) -> bool
pub const fn has_icon(&self) -> bool
Returns true if this menu item has an assigned stock-art icon.
Sourcepub const fn is_enabled(&self) -> bool
pub const fn is_enabled(&self) -> bool
Returns true if this item is enabled.
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Sets the enabled state.
Sourcepub const fn is_checkable(&self) -> bool
pub const fn is_checkable(&self) -> bool
Returns true if this item is checkable.
Sourcepub const fn is_checked(&self) -> bool
pub const fn is_checked(&self) -> bool
Returns true if this item is currently checked.
Sourcepub fn set_checked(&mut self, checked: bool)
pub fn set_checked(&mut self, checked: bool)
Sets the checked state.
Returns the attached submenu id, if any.
Sourcepub fn translated_label(&self, style: AccessKeyStyle) -> String
pub fn translated_label(&self, style: AccessKeyStyle) -> String
Returns the label translated to the specified lane access-key style.