Skip to main content

MenuItemSpec

Struct MenuItemSpec 

Source
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: MenuItemId

Stable application-facing item identifier.

§label: String

Visible 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: bool

Whether the menu item can be activated.

§visible: bool

Whether the menu item is visible.

§checkable: bool

Whether the menu item supports a checked/toggle state.

§checked: bool

Current checked state for checkable items.

§submenu: Option<MenuId>

Optional submenu identifier attached to this item.

Implementations§

Source§

impl MenuItemSpec

Source

pub fn new(id: MenuItemId, label: impl Into<String>) -> Self

Creates an enabled, visible, plain menu item specification.

Source

pub fn unassigned(label: impl Into<String>) -> Self

Creates an unassigned menu item specification with a placeholder ID (0).

Source

pub fn with_shortcut(self, shortcut: impl Into<String>) -> Self

Sets the keyboard shortcut hint (e.g. "Ctrl+N").

Source

pub fn with_icon(self, icon: IconRole) -> Self

Sets the stock-art icon role.

Source

pub fn with_optional_icon(self, icon: Option<IconRole>) -> Self

Sets or clears the stock-art icon role with an optional value.

Source

pub fn with_icon_identifier(self, identifier: &str) -> Self

Sets the stock-art icon role from its stable identifier (e.g. "new", "open").

Source

pub fn with_enabled(self, enabled: bool) -> Self

Sets the enabled state.

Source

pub fn with_visible(self, visible: bool) -> Self

Sets the visibility state.

Source

pub fn with_checkable(self) -> Self

Marks the menu item as checkable.

Source

pub fn with_checked(self, checked: bool) -> Self

Sets the checked state (and marks the item as checkable).

Source

pub fn with_submenu(self, submenu: MenuId) -> Self

Sets the attached submenu id.

Source

pub fn with_label(self, label: impl Into<String>) -> Self

Sets the visible label.

Source

pub fn with_text(self, text: impl Into<String>) -> Self

Sets the visible text (alias for Self::with_label).

Source

pub const fn id(&self) -> MenuItemId

Returns the item’s identifier.

Source

pub fn label(&self) -> &str

Returns the item’s visible label.

Source

pub fn text(&self) -> &str

Returns the item’s text (alias for Self::label).

Source

pub fn set_label(&mut self, label: impl Into<String>)

Sets the item’s visible label.

Source

pub fn set_text(&mut self, text: impl Into<String>)

Sets the item’s visible text (alias for Self::set_label).

Source

pub fn shortcut(&self) -> Option<&str>

Returns the optional keyboard shortcut hint.

Source

pub fn set_shortcut(&mut self, shortcut: Option<String>)

Sets the optional keyboard shortcut.

Source

pub const fn icon(&self) -> Option<IconRole>

Returns the assigned stock-art icon role, if any.

Source

pub fn icon_identifier(&self) -> Option<&'static str>

Returns the stable string identifier of the icon, if one is set.

Source

pub fn set_icon(&mut self, icon: Option<IconRole>)

Sets or clears the stock-art icon role.

Source

pub const fn has_icon(&self) -> bool

Returns true if this menu item has an assigned stock-art icon.

Source

pub const fn is_enabled(&self) -> bool

Returns true if this item is enabled.

Source

pub fn set_enabled(&mut self, enabled: bool)

Sets the enabled state.

Source

pub const fn is_checkable(&self) -> bool

Returns true if this item is checkable.

Source

pub const fn is_checked(&self) -> bool

Returns true if this item is currently checked.

Source

pub fn set_checked(&mut self, checked: bool)

Sets the checked state.

Source

pub const fn submenu(&self) -> Option<MenuId>

Returns the attached submenu id, if any.

Source

pub fn translated_label(&self, style: AccessKeyStyle) -> String

Returns the label translated to the specified lane access-key style.

Trait Implementations§

Source§

impl Clone for MenuItemSpec

Source§

fn clone(&self) -> Self

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 MenuItemSpec

Source§

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

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

impl Default for MenuItemSpec

Source§

fn default() -> Self

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

impl Eq for MenuItemSpec

Source§

impl From<MenuItemSpec> for MenuItem

Source§

fn from(spec: MenuItemSpec) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for MenuItemSpec

Source§

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

Auto Trait Implementations§

§

impl Forget for MenuItemSpec

§

impl Freeze for MenuItemSpec
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for MenuItemSpec

§

impl RefUnwindSafe for MenuItemSpec

§

impl Send for MenuItemSpec
where RawVecInner: Send,

§

impl Sync for MenuItemSpec
where RawVecInner: Sync,

§

impl Unpin for MenuItemSpec
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for MenuItemSpec

§

impl UnwindSafe for MenuItemSpec
where RawVecInner: UnwindSafe,

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.