Expand description
MenuItem — a single command row in a menu or context menu.
Each item consists of an optional leading icon, a label, an optional
trailing shortcut label, and an activation closure. MenuItem is
non-generic: actions are type-erased closures identical to Button’s
on_activate_fn model. Submenus are declared with MenuItem::submenu
— the factory builds the nested MenuList lazily at hover time.
Every item operates in one of three modes selected by builder methods:
| Builder | AT Role | Leading glyph |
|---|---|---|
| (default) | Role::MenuItem | icon or blank |
.checked(signal) | Role::MenuItemCheckBox | checkmark / blank |
.check_state(signal) | Role::MenuItemCheckBox | check / dash / blank |
.reflect_checked(signal) | Role::MenuItemCheckBox | checkmark (read-only) |
.radio(value, selected) | Role::MenuItemRadio | filled dot / blank |
Check and radio modes are mutually exclusive with .icon(...) — the
Windows convention reserves the leading slot for state glyphs on
checkable items; a debug_assert! fires when both are set.
§An icon that keeps its own colour
.icon(...) recolours whatever it is handed with the row’s text role, so the
glyph follows hover, press and disabled alongside the label. That is right for
an icon that says the same thing as the label, and wrong for one whose colour
is the content — a tag’s swatch, a status light, a colour a person chose.
.icon_keeps_color() leaves it alone. Two costs come with it: the icon no
longer follows the highlight (on a style whose highlighted row is a solid
accent fill, it has to carry its own contrast against that fill), and a
literal colour does not dim in a disabled row — ColorProp::Static and
Bound ignore the enabled state, while every role variant substitutes its
disabled counterpart. An icon that should dim wants a role, and then it does
not want this at all.
let swatch = IconWidget::from_path(Path::circle(Point::new(5.0, 5.0), 4.5), 10.0)
.color(Color::from_hex("#e91e63"));
let _w = MenuItem::new(lit!("Characters"))
.icon(swatch)
.icon_keeps_color();Mnemonic markers use the in-string & convention (&Save →
underline ‘S’ when Alt is held; && → literal &). The enclosing
MenuList wires bare-letter in-menu activation automatically.
let _w = MenuItem::new(lit!("&Save"))
.on_activate_fn(|ctx| ctx.send_intent(Intent::new("app.save")));Structs§
- Menu
Item - A single command row in a
MenuListor context menu.