pub struct MenuItem<T> { /* private fields */ }
Expand description
An item in a menu.
See the module level documentation for more on how to use menus.
Implementations§
source§impl<T: Data> MenuItem<T>
impl<T: Data> MenuItem<T>
sourcepub fn new(title: impl Into<LabelText<T>>) -> MenuItem<T>
pub fn new(title: impl Into<LabelText<T>>) -> MenuItem<T>
Create a new menu item with a given name.
sourcepub fn on_activate(
self,
on_activate: impl FnMut(&mut MenuEventCtx<'_>, &mut T, &Env) + 'static
) -> Self
pub fn on_activate(
self,
on_activate: impl FnMut(&mut MenuEventCtx<'_>, &mut T, &Env) + 'static
) -> Self
Provide a callback that will be invoked when this menu item is chosen.
sourcepub fn command(self, cmd: impl Into<Command>) -> Self
pub fn command(self, cmd: impl Into<Command>) -> Self
Provide a Command
that will be sent when this menu item is chosen.
This is equivalent to self.on_activate(move |ctx, _data, _env| ctx.submit_command(cmd))
.
If the command’s target is Target::Auto
, it will be sent to the menu’s window if the
menu is associated with a window, or to Target::Global
if the menu is not associated
with a window.
sourcepub fn hotkey(self, mods: impl Into<Option<RawMods>>, key: impl IntoKey) -> Self
pub fn hotkey(self, mods: impl Into<Option<RawMods>>, key: impl IntoKey) -> Self
Provide a hotkey for activating this menu item.
This is equivalent to
self.dynamic_hotkey(move |_, _| Some(HotKey::new(mods, key))
sourcepub fn dynamic_hotkey(
self,
hotkey: impl FnMut(&T, &Env) -> Option<HotKey> + 'static
) -> Self
pub fn dynamic_hotkey(
self,
hotkey: impl FnMut(&T, &Env) -> Option<HotKey> + 'static
) -> Self
Provide a dynamic hotkey for activating this menu item.
The hotkey can change depending on the data.
sourcepub fn enabled_if(self, enabled: impl FnMut(&T, &Env) -> bool + 'static) -> Self
pub fn enabled_if(self, enabled: impl FnMut(&T, &Env) -> bool + 'static) -> Self
Provide a callback for determining whether this menu item should be enabled.
Whenever the callback returns true
, the item will be enabled.