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>
impl<Msg> MenuItem<Msg>
Sourcepub fn new(label: impl Into<String>, message: Msg) -> Self
pub fn new(label: impl Into<String>, message: Msg) -> Self
A row of words: the ordinary item, and what
PopupMenuButton::item builds.
Sourcepub fn widget(child: impl Widget<Msg> + 'static, message: Msg) -> Self
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.
Sourcepub fn icon(icon: IconData, label: impl Into<String>, message: Msg) -> Self
pub fn icon(icon: IconData, label: impl Into<String>, message: Msg) -> Self
A row with a picture in the leading column.
Sourcepub fn checked(label: impl Into<String>, checked: bool, message: Msg) -> Self
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.
Sourcepub fn divider() -> Self
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.
Sourcepub fn enabled(self, enabled: bool) -> Self
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.
Sourcepub fn shortcut(self, keys: impl Into<String>) -> Self
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.