Skip to main content

MenuItem

Struct MenuItem 

Source
pub struct MenuItem { /* private fields */ }
Expand description

A menu item: a title, what choosing it does, and optionally a shortcut, a check mark and a role. Its title, enabled state, check mark and visibility take a literal, a signal or a closure.

ⓘ
MenuItem::new("Save").shortcut(Shortcut::primary('s')).on_select(save)
MenuItem::new("Show Sidebar").bind(sidebar)
MenuItem::new("Large").radio((zoom, Zoom::Large))

In view!, its text is its title: <MenuItem shortcut=Shortcut::primary('s') @select=save>"Save"</MenuItem>.

Implementations§

Source§

impl MenuItem

Source

pub fn new(title: impl IntoValue<String>) -> MenuItem

Source

pub fn on_select(self, handler: impl Fn() + 'static) -> MenuItem

Called when the item is chosen: clicked, or through its shortcut.

Source

pub fn shortcut(self, shortcut: impl Into<Option<Shortcut>>) -> MenuItem

The item’s shortcut, or None for none: some items have one only on some platforms.

Source

pub fn enabled(self, enabled: impl IntoValue<bool>) -> MenuItem

Source

pub fn visible(self, visible: impl IntoValue<bool>) -> MenuItem

In the menu while true.

Source

pub fn checked(self, checked: impl IntoValue<bool>) -> MenuItem

Shows a check mark while true. Choosing the item only calls its handler: bind toggles a signal instead.

Source

pub fn bind(self, signal: Signal<bool>) -> MenuItem

A check mark showing the signal; choosing the item toggles it.

Source

pub fn radio<T: PartialEq + Clone + 'static>( self, (signal, value): (Signal<T>, T), ) -> MenuItem

One of a group of choices: checked while signal holds value, and choosing it sets it. Radio items next to each other in a menu form a group. A pair, so view! can write radio=(zoom, Zoom::Large).

Source

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

An item every app has, which platforms may move to a place of their own and give their own title and shortcut: see MenuRole.

Trait Implementations§

Auto Trait Implementations§

§

impl !RefUnwindSafe for MenuItem

§

impl !Send for MenuItem

§

impl !Sync for MenuItem

§

impl !UnwindSafe for MenuItem

§

impl Forget for MenuItem

§

impl Freeze for MenuItem
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn Fn() -> String> is !null: Freeze, PhantomData<RcInner<dyn Fn() -> String>>: Freeze, *const RcInner<dyn Fn() -> bool> is !null: Freeze, PhantomData<RcInner<dyn Fn() -> bool>>: Freeze, *const RcInner<dyn Fn()> is !null: Freeze, PhantomData<RcInner<dyn Fn()>>: Freeze,

§

impl Move for MenuItem

§

impl Unpin for MenuItem
where *const u8 is !null: Unpin, Rc<dyn Fn() -> String>: Unpin, Rc<dyn Fn() -> bool>: Unpin, Rc<dyn Fn()>: Unpin,

§

impl UnsafeUnpin for MenuItem
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn Fn() -> String> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn() -> String>>: UnsafeUnpin, *const RcInner<dyn Fn() -> bool> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn() -> bool>>: UnsafeUnpin, *const RcInner<dyn Fn()> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn()>>: UnsafeUnpin,

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