Struct native_windows_gui::MenuItem
source · [−]pub struct MenuItem {
pub handle: ControlHandle,
}
Expand description
A windows menu item. Can be added to a menubar or another menu.
Requires the menu
feature.
Builder parameters:
- text: The text of the menu, including access key and shortcut label
- disabled: If the item can be selected by the user
- check: If the item should have a check mark next to it.
- parent: A top level window or a menu. With a top level window, the menu item is added to the menu bar.
Control events:
- OnMenuItemSelected: When a menu item is selected. This can be done by clicking or using the hot-key.
- OnMenuHover: When the user hovers the menu
Menu Access Keys
Just like Menus, menu items can have access keys. An access key is an underlined letter in the text of a menu item. When a menu is active, the user can select a menu item by pressing the key that corresponds to the item’s underlined letter. The user makes the menu bar active by pressing the ALT key to highlight the first item on the menu bar. A menu is active when it is displayed.
To create an access key for a menu item, precede any character in the item’s text string with an ampersand. For example, the text string “&Move” causes the system to underline the letter “M”.
use native_windows_gui as nwg;
fn menu_item(item: &mut nwg::MenuItem, menu: &nwg::Menu) -> Result<(), nwg::NwgError> {
nwg::MenuItem::builder()
.text("&Hello")
.disabled(true)
.parent(menu)
.build(item)
}
Shortcut Label
A shortcut label like “Ctrl+O” can be added with the text
field. By prefixing the shortcut with a tab character \t
and
adding it as a suffix to the text label, it will be rendered right-aligned in the menu item.
For example, an “Exit” menu item could have both an access key “E” and a shortcut label “Alt+F4” with text: "&Exit\tAlt+F4"
.
note: This will only add a text label to the menu item, the keyboard handling must be done through other means.
use native_windows_gui as nwg;
fn menu(menu: &mut nwg::Menu, window: &nwg::Window) -> Result<(), nwg::NwgError> {
nwg::Menu::builder()
.text("&Exit\tAlt+F4")
.disabled(false)
.parent(window)
.build(menu)
}
Fields
handle: ControlHandle
Implementations
sourceimpl MenuItem
impl MenuItem
pub fn builder<'a>() -> MenuItemBuilder<'a>
sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Return true if the control user can interact with the control, return false otherwise
sourcepub fn set_enabled(&self, v: bool)
pub fn set_enabled(&self, v: bool)
Enable or disable the control
sourcepub fn set_checked(&self, check: bool)
pub fn set_checked(&self, check: bool)
Sets the check state of a menu item
Trait Implementations
sourceimpl From<&MenuItem> for ControlHandle
impl From<&MenuItem> for ControlHandle
sourceimpl From<&mut MenuItem> for ControlHandle
impl From<&mut MenuItem> for ControlHandle
sourceimpl PartialEq<ControlHandle> for MenuItem
impl PartialEq<ControlHandle> for MenuItem
sourcefn eq(&self, other: &ControlHandle) -> bool
fn eq(&self, other: &ControlHandle) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<MenuItem> for ControlHandle
impl PartialEq<MenuItem> for ControlHandle
sourceimpl PartialEq<MenuItem> for MenuItem
impl PartialEq<MenuItem> for MenuItem
impl Eq for MenuItem
impl StructuralEq for MenuItem
impl StructuralPartialEq for MenuItem
Auto Trait Implementations
impl RefUnwindSafe for MenuItem
impl !Send for MenuItem
impl !Sync for MenuItem
impl Unpin for MenuItem
impl UnwindSafe for MenuItem
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more