Skip to main content

MenuEntry

Struct MenuEntry 

Source
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

Source

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.

Source

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.

Source

pub fn action(self, f: impl Fn() + 'static) -> MenuEntry

Run f when the item is chosen.

Source

pub fn shortcut(self, s: Shortcut) -> MenuEntry

Full shortcut spec, e.g. Shortcut::primary("s").shift().

Source

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.

Source

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.

Source

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()))
Source

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

pub fn role(self, role: MenuRole) -> MenuEntry

Tag a custom command with a standard day_spec::MenuRole (usually you use menu_role).

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.

ⓘ
sub_menu(res::str::menu_file(), menu_items).bar_role(MenuBarRole::File)
Source

pub fn bar_role(self, role: MenuBarRole) -> MenuEntry

Trait Implementations§

Source§

impl Clone for MenuEntry

Source§

fn clone(&self) -> MenuEntry

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

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
§

impl<T> ErasedDestructor for T
where T: 'static,

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> 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> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

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.
Day API ↩ Guides· daybrite.dev