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
label: SharedStringdescription: 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.
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.
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.
Separator
Implementations§
Source§impl Item
impl Item
pub fn action(label: impl Into<SharedString>) -> Self
Sourcepub fn with_icon(self, icon: impl Into<Icon>) -> Self
pub fn with_icon(self, icon: impl Into<Icon>) -> Self
No-ops on a separator, which has nothing to hang a glyph on.
Sourcepub fn with_description(self, description: impl Into<SharedString>) -> Self
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.
Sourcepub fn with_long_description(self, description: impl Into<SharedString>) -> Self
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.
Sourcepub fn with_tooltip(self, tooltip: impl Into<SharedString>) -> Self
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.
Sourcepub fn with_keystroke(self, keystroke: impl Into<SharedString>) -> Self
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.
Sourcepub fn with_shortcut(self, action: &dyn Action, window: &Window) -> Self
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.
Sourcepub fn with_shortcut_in(
self,
action: &dyn Action,
context: &str,
window: &Window,
) -> Self
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).
Sourcepub fn checked(self, checked: bool) -> Self
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.
pub fn disabled(self) -> Self
Sourcepub fn selectable(&self) -> bool
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§
impl Eq for Item
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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