Skip to main content

ContextMenuItem

Struct ContextMenuItem 

Source
pub struct ContextMenuItem {
    pub id: String,
    pub label: String,
    pub shortcut: Option<KeyboardShortcut>,
    pub enabled: bool,
    pub separator_after: bool,
    pub icon: Option<String>,
}
Expand description

A single item in a context menu

Represents a menu item with optional shortcuts, icons, and visual separators. Items can be enabled or disabled to control user interaction.

Fields§

§id: String

Unique identifier for the item

§label: String

Display label

§shortcut: Option<KeyboardShortcut>

Optional keyboard shortcut hint

§enabled: bool

Whether the item is enabled

§separator_after: bool

Whether to show a separator after this item

§icon: Option<String>

Optional icon identifier

Implementations§

Source§

impl ContextMenuItem

Source

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

Create a new context menu item

§Example
let item = ContextMenuItem::new("copy", "Copy");
Source

pub fn with_shortcut(self, shortcut: KeyboardShortcut) -> Self

Add a keyboard shortcut to this item

The shortcut will be displayed as a hint next to the item label.

§Example
let item = ContextMenuItem::new("copy", "Copy")
    .with_shortcut(KeyboardShortcut::command(KeyCode::C));
Source

pub fn disabled(self) -> Self

Mark this item as disabled

Disabled items will be displayed but cannot be clicked.

§Example
let item = ContextMenuItem::new("paste", "Paste").disabled();
Source

pub fn with_separator(self) -> Self

Add a separator after this item

A visual separator line will be drawn after this item in the menu.

§Example
let item = ContextMenuItem::new("copy", "Copy").with_separator();
Source

pub fn with_icon(self, icon: impl Into<String>) -> Self

Add an icon to this item

The icon identifier can be used by the renderer to display an icon next to the menu item.

§Example
let item = ContextMenuItem::new("open", "Open")
    .with_icon("folder-open");
Source

pub fn separator() -> Self

Create a separator-only item

This creates a non-interactive item that only displays a separator. The item will have an empty label and be disabled.

§Example
let items = vec![
    ContextMenuItem::new("copy", "Copy"),
    ContextMenuItem::separator(),
    ContextMenuItem::new("paste", "Paste"),
];
Source

pub fn is_separator(&self) -> bool

Check if this is a separator-only item

Trait Implementations§

Source§

impl Clone for ContextMenuItem

Source§

fn clone(&self) -> ContextMenuItem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContextMenuItem

Source§

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

Formats the value using the given formatter. Read more

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