Skip to main content

MenuItem

Struct MenuItem 

Source
pub struct MenuItem<Msg = Callback> { /* private fields */ }
Expand description

One entry of a PopupMenuButton’s list: an action, or the rule between two groups of them.

The shorthands on the button itself — item, icon_item, checked_item, item_widget and divider — each build one of these, and are what most call sites should write. This type is the door to the two things a shorthand cannot carry: a row that is not available while the rest of the menu is, and the keys that work an action.

use frus_widgets::{Container, Icons, MenuItem, PopupMenuButton};

#[derive(Clone)]
enum Msg {
    Close,
    Cut,
    Paste,
    Wrap,
}

let menu = PopupMenuButton::new(Container::<Msg>::new(), true, Msg::Close)
    .entry(MenuItem::icon(Icons::CONTENT_CUT, "Cut", Msg::Cut).shortcut("Ctrl+X"))
    .entry(MenuItem::new("Paste", Msg::Paste).enabled(false))
    .divider()
    .checked_item("Word wrap", true, Msg::Wrap);

Implementations§

Source§

impl<Msg> MenuItem<Msg>

Source

pub fn new(label: impl Into<String>, message: Msg) -> Self

A row of words: the ordinary item, and what PopupMenuButton::item builds.

Source

pub fn widget(child: impl Widget<Msg> + 'static, message: Msg) -> Self

A row the caller draws: two lines, a colour swatch, a badge, rich text — whatever the menu is for.

It is laid out in exactly the room a label would have had, columns and all, and it grows: a row of words is a tap target tall, a row of anything else is at least that and as much more as it needs.

Source

pub fn icon(icon: IconData, label: impl Into<String>, message: Msg) -> Self

A row with a picture in the leading column.

Source

pub fn checked(label: impl Into<String>, checked: bool, message: Msg) -> Self

A row that is on or off, ticked when it is on.

It still takes a message, and turning it over is still the application’s job: this says what the state is, not what it will be.

Source

pub fn divider() -> Self

The rule between two groups of actions. It answers nothing, takes no focus, and is not a row’s height: sixteen, the room a separator needs to read as one.

Source

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

Whether this row can be used, over the menu’s own availability.

A disabled row is still drawn and still read out — greyed, announced as disabled, and returning no message. An action that is missing from the list altogether tells a reader nothing about why.

Source

pub fn shortcut(self, keys: impl Into<String>) -> Self

The keys that work this action, shown muted on the right.

The text is the caller’s, not a key combination this framework parses: the spelling differs by platform (Ctrl+X, ⌘X) and nothing here knows which one an application means. It is announced after the label, since a reader who cannot see it has no other way to hear it.

Auto Trait Implementations§

§

impl<Msg = Callback> !RefUnwindSafe for MenuItem<Msg>

§

impl<Msg = Callback> !Send for MenuItem<Msg>

§

impl<Msg = Callback> !Sync for MenuItem<Msg>

§

impl<Msg = Callback> !UnwindSafe for MenuItem<Msg>

§

impl<Msg> Freeze for MenuItem<Msg>
where Option<Rc<dyn Widget<Msg>>>: Freeze, Option<Msg>: Freeze,

§

impl<Msg> Unpin for MenuItem<Msg>
where Option<Rc<dyn Widget<Msg>>>: Unpin, Option<Msg>: Unpin,

§

impl<Msg> UnsafeUnpin for MenuItem<Msg>
where Option<Rc<dyn Widget<Msg>>>: UnsafeUnpin, Option<Msg>: 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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
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.