pub struct Menu { /* private fields */ }Expand description
A root menu that can be added to a Window on Windows and Linux and used as the app global menu on macOS.
Implementations§
Source§impl Menu
impl Menu
Sourcepub fn with_items(items: &[&dyn IsMenuItem]) -> Result<Self>
pub fn with_items(items: &[&dyn IsMenuItem]) -> Result<Self>
Creates a new menu with given items. It calls Menu::new and Menu::append_items internally.
Sourcepub fn with_id_and_items<I: Into<MenuId>>(
id: I,
items: &[&dyn IsMenuItem],
) -> Result<Self>
pub fn with_id_and_items<I: Into<MenuId>>( id: I, items: &[&dyn IsMenuItem], ) -> Result<Self>
Creates a new menu with the specified id and given items. It calls Menu::new and Menu::append_items internally.
Sourcepub fn append(&self, item: &dyn IsMenuItem) -> Result<()>
pub fn append(&self, item: &dyn IsMenuItem) -> Result<()>
Add a menu item to the end of this menu.
Sourcepub fn append_items(&self, items: &[&dyn IsMenuItem]) -> Result<()>
pub fn append_items(&self, items: &[&dyn IsMenuItem]) -> Result<()>
Add menu items to the end of this menu. It calls Menu::append in a loop internally.
Sourcepub fn prepend(&self, item: &dyn IsMenuItem) -> Result<()>
pub fn prepend(&self, item: &dyn IsMenuItem) -> Result<()>
Add a menu item to the beginning of this menu.
Sourcepub fn prepend_items(&self, items: &[&dyn IsMenuItem]) -> Result<()>
pub fn prepend_items(&self, items: &[&dyn IsMenuItem]) -> Result<()>
Add menu items to the beginning of this menu. It calls Menu::insert_items with position of 0 internally.
Sourcepub fn insert(&self, item: &dyn IsMenuItem, position: usize) -> Result<()>
pub fn insert(&self, item: &dyn IsMenuItem, position: usize) -> Result<()>
Insert a menu item at the specified postion in the menu.
Sourcepub fn insert_items(
&self,
items: &[&dyn IsMenuItem],
position: usize,
) -> Result<()>
pub fn insert_items( &self, items: &[&dyn IsMenuItem], position: usize, ) -> Result<()>
Insert menu items at the specified postion in the menu.
Sourcepub fn remove(&self, item: &dyn IsMenuItem) -> Result<()>
pub fn remove(&self, item: &dyn IsMenuItem) -> Result<()>
Remove a menu item from this menu.
Sourcepub fn remove_at(&self, position: usize) -> Option<MenuItemKind>
pub fn remove_at(&self, position: usize) -> Option<MenuItemKind>
Remove the menu item at the specified position from this menu and returns it.
Sourcepub fn items(&self) -> Vec<MenuItemKind>
pub fn items(&self) -> Vec<MenuItemKind>
Returns a list of menu items that has been added to this menu.
Sourcepub unsafe fn init_for_hwnd(&self, hwnd: isize) -> Result<()>
pub unsafe fn init_for_hwnd(&self, hwnd: isize) -> Result<()>
Adds this menu to a win32 window.
§Safety
The hwnd must be a valid window HWND.
§Note about accelerators:
For accelerators to work, the event loop needs to call
TranslateAcceleratorW
with the HACCEL returned from Menu::haccel
§Example:
let menu = Menu::new();
unsafe {
let mut msg: MSG = std::mem::zeroed();
while GetMessageW(&mut msg, std::ptr::null_mut(), 0, 0) == 1 {
let translated = TranslateAcceleratorW(msg.hwnd, menu.haccel() as _, &msg as *const _);
if translated != 1{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
}Sourcepub unsafe fn init_for_hwnd_with_theme(
&self,
hwnd: isize,
theme: MenuTheme,
) -> Result<()>
pub unsafe fn init_for_hwnd_with_theme( &self, hwnd: isize, theme: MenuTheme, ) -> Result<()>
Adds this menu to a win32 window using the specified theme.
See Menu::init_for_hwnd for more info.
Note that the theme only affects the menu bar itself and not submenus or context menu.
§Safety
The hwnd must be a valid window HWND.
Sourcepub unsafe fn set_theme_for_hwnd(
&self,
hwnd: isize,
theme: MenuTheme,
) -> Result<()>
pub unsafe fn set_theme_for_hwnd( &self, hwnd: isize, theme: MenuTheme, ) -> Result<()>
Set a theme for the menu bar on this window.
Note that the theme only affects the menu bar itself and not submenus or context menu.
§Safety
The hwnd must be a valid window HWND.
Sourcepub fn haccel(&self) -> isize
pub fn haccel(&self) -> isize
Returns The HACCEL associated with this menu
It can be used with TranslateAcceleratorW
in the event loop to enable accelerators
Sourcepub unsafe fn remove_for_hwnd(&self, hwnd: isize) -> Result<()>
pub unsafe fn remove_for_hwnd(&self, hwnd: isize) -> Result<()>
Sourcepub unsafe fn hide_for_hwnd(&self, hwnd: isize) -> Result<()>
pub unsafe fn hide_for_hwnd(&self, hwnd: isize) -> Result<()>
Sourcepub unsafe fn show_for_hwnd(&self, hwnd: isize) -> Result<()>
pub unsafe fn show_for_hwnd(&self, hwnd: isize) -> Result<()>
Sourcepub unsafe fn is_visible_on_hwnd(&self, hwnd: isize) -> bool
pub unsafe fn is_visible_on_hwnd(&self, hwnd: isize) -> bool
Returns whether this menu visible on a on a win32 window
§Safety
The hwnd must be a valid window HWND.