Skip to main content

Item

Enum Item 

Source
pub enum Item {
    Action {
        label: SharedString,
        description: Option<SharedString>,
        tooltip: Option<SharedString>,
        icon: Option<Icon>,
        keystroke: Option<SharedString>,
        checked: bool,
        enabled: bool,
    },
    Submenu {
        label: SharedString,
        icon: Option<Icon>,
        enabled: bool,
        items: Vec<Item>,
    },
    Separator,
}
Expand description

A row in a menu.

Deliberately not a struct with an is_separator flag: a separator has no label, no accelerator and nothing to enable, and every one of those fields would have to be answered anyway.

Variants§

§

Action

Fields

§description: Option<SharedString>

A second line under the label, for a row whose name does not say enough on its own — what a command will do, which file it will act on. None keeps the row one line tall; nothing reserves space for a description the way the glyph gutter reserves space for an icon, because a row’s two lines read as one block and a blank second line would read as a gap.

§tooltip: Option<SharedString>

Hover text for the row, shown after gpui’s tooltip delay. Where the whole of a Item::with_description too long for its one line goes, and where a disabled row says why — a disabled row takes no click, but it still takes a tooltip.

§icon: Option<Icon>

The leading glyph. A menu where no row has one keeps no room for it.

§keystroke: Option<SharedString>

The accelerator to print — the binding itself is the app’s, and bezel never dispatches it. A menu that showed a keystroke it did not own would be documenting a lie, which is what Item::with_shortcut fills this from the keymap to avoid.

§checked: bool

The choice the menu is currently on, marked with a trailing check.

§enabled: bool
§

Submenu

A row that drops a menu of its own, the way a SwiftUI Menu nests inside a Menu. It carries no accelerator and nothing to check: the only thing choosing it does is open.

Fields

§icon: Option<Icon>
§enabled: bool
§items: Vec<Item>
§

Separator

Implementations§

Source§

impl Item

Source

pub fn action(label: impl Into<SharedString>) -> Self

Source

pub fn submenu(label: impl Into<SharedString>, items: Vec<Item>) -> Self

Source

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

No-ops on a separator, which has nothing to hang a glyph on.

Source

pub fn with_description(self, description: impl Into<SharedString>) -> Self

A second line under the label. No-ops on anything but an action row: a submenu’s second line is the panel it opens, and a separator has no first line to put one under.

Source

pub fn with_long_description(self, description: impl Into<SharedString>) -> Self

The description and the whole of it on hover, from one string. A sentence long enough to need clipping is one no caller should have to write twice — two copies of it drift.

Source

pub fn with_tooltip(self, tooltip: impl Into<SharedString>) -> Self

Hover text for the row — the rest of a description the row had to clip, or why a disabled row is disabled. No-ops on anything but an action row: a submenu row is already hovered to open it, and a label the pointer waits on top of would fight the panel it drops.

Source

pub fn with_keystroke(self, keystroke: impl Into<SharedString>) -> Self

No-ops on anything but an action row: a submenu’s keystroke is the arrow that opens it, and a separator has nothing to hang one on.

Source

pub fn with_shortcut(self, action: &dyn Action, window: &Window) -> Self

The accelerator read off the keymap instead of typed in — the same slot Item::with_keystroke fills, filled with what would actually fire. An action with nothing bound to it leaves the row bare, because a menu that prints a chord it no longer owns is documenting a lie.

Still nothing to dispatch: the row’s click stays the caller’s, and the action passed here is read, never run.

Source

pub fn with_shortcut_in( self, action: &dyn Action, context: &str, window: &Window, ) -> Self

Item::with_shortcut for a chord bound to a surface that is not focused — which is most menu rows, since opening the menu took focus off whatever the row acts on. context is the one the binding was scoped to (editor::CONTEXT, crate::input::KEY_CONTEXT).

Source

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

Takes the flag, because what a menu is on is decided per render. No-ops on a submenu, which is not itself a choice.

Source

pub fn disabled(self) -> Self

Source

pub fn selectable(&self) -> bool

Whether the keyboard and the pointer can land here at all. A submenu with nothing to choose in it counts as unlandable: opening it would drop a panel that is a dead end.

Trait Implementations§

Source§

impl Clone for Item

Source§

fn clone(&self) -> Item

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 Item

Source§

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

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

impl Eq for Item

Source§

impl PartialEq for Item

Source§

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

Auto Trait Implementations§

§

impl Freeze for Item

§

impl RefUnwindSafe for Item

§

impl Send for Item

§

impl Sync for Item

§

impl Unpin for Item

§

impl UnsafeUnpin for Item

§

impl UnwindSafe for Item

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more