pub struct MenuEntry { /* private fields */ }Expand description
A menu entry under construction. Build a command with menu_item, a nested submenu with
sub_menu, a standard system command with menu_role, and a divider with menu_separator.
Attach to a Piece via Decorate::context_menu or install app-wide via app_menu.
Implementations§
Source§impl MenuEntry
impl MenuEntry
Sourcepub fn icon(self, s: Symbol) -> MenuEntry
pub fn icon(self, s: Symbol) -> MenuEntry
A standard Symbol beside the item’s title, drawn with the
platform’s glyph, the same vocabulary toolbars take. Menus carry icons on macOS,
Windows, GNOME, KDE and Android; a backend whose menus are text-only ignores it, so an
icon is always an addition to a menu that already reads correctly without one.
Sourcepub fn image(self, name: impl Into<String>) -> MenuEntry
pub fn image(self, name: impl Into<String>) -> MenuEntry
A bundled image from resource/images, for an item the standard set has no glyph for:
an app’s own vocabulary (a shape, a brand). Same rule as MenuEntry::icon.
Sourcepub fn shortcut(self, s: Shortcut) -> MenuEntry
pub fn shortcut(self, s: Shortcut) -> MenuEntry
Full shortcut spec, e.g. Shortcut::primary("s").shift().
Sourcepub fn key(self, key: impl Into<String>) -> MenuEntry
pub fn key(self, key: impl Into<String>) -> MenuEntry
Convenience: the platform’s primary modifier (⌘ / Ctrl) + key. This sets the item’s
shortcut; to name the item, use MenuEntry::id.
Sourcepub fn id(self, id: ElementId) -> MenuEntry
pub fn id(self, id: ElementId) -> MenuEntry
Name this item, so something outside the menu can address it: a dayscript
menu: { id: "view-both" } step, or a tap on the composed menu’s row where the platform
has no native menus.
A label cannot do that job. It is localized, so it changes with the run’s language, and an
item that shows its own state changes it whenever the state moves, which is exactly the
case MenuEntry::checked creates. Give an id to any item a script drives.
Sourcepub fn checked<M>(self, on: impl IntoReactive<bool, M>) -> MenuEntry
pub fn checked<M>(self, on: impl IntoReactive<bool, M>) -> MenuEntry
Draw this item with the platform’s check mark, on or off, for a setting the menu toggles or one of several mutually exclusive choices. An item that never calls this is a plain command and reserves no room for a mark.
Choosing the item still runs its action; no backend flips the mark
by itself. The app owns the state: pass the signal (or a closure reading it) and the mark
follows the state, the menu re-lowering when it changes.
menu_item(tr("view_grid")).id(day_core::id!(view_grid)).checked(grid).action(move || grid.set(!grid.get()))Sourcepub fn enabled<M>(self, on: impl IntoReactive<bool, M>) -> MenuEntry
pub fn enabled<M>(self, on: impl IntoReactive<bool, M>) -> MenuEntry
Whether the item can be chosen (default true): a constant, a Signal<bool>, or a
closure, re-read whenever the menu is lowered.
Source§impl MenuEntry
Claim one of the platform’s standard menu-bar slots for this submenu: the backend places it
where that menu belongs and does not add its stock version. Without a role, a submenu is
an app menu and sits between the standard ones.
impl MenuEntry
Claim one of the platform’s standard menu-bar slots for this submenu: the backend places it where that menu belongs and does not add its stock version. Without a role, a submenu is an app menu and sits between the standard ones.
sub_menu(res::str::menu_file(), menu_items).bar_role(MenuBarRole::File)pub fn bar_role(self, role: MenuBarRole) -> MenuEntry
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MenuEntry
impl !Send for MenuEntry
impl !Sync for MenuEntry
impl !UnwindSafe for MenuEntry
impl Freeze for MenuEntry
impl Unpin for MenuEntry
impl UnsafeUnpin for MenuEntry
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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