pub struct MenuBuilder<'m, R: Runtime, M: Manager<R>> { /* private fields */ }desktop only.Expand description
A builder type for Menu
§Platform-specific:
- macOS: if using
MenuBuilderfor the global menubar, it can only containSubmenus
§Example
use tauri::menu::*;
tauri::Builder::default()
.setup(move |app| {
let handle = app.handle();
let menu = MenuBuilder::new(handle)
.item(&MenuItem::new(handle, "MenuItem 1", true, None::<&str>)?)
.items(&[
&CheckMenuItem::new(handle, "CheckMenuItem 1", true, true, None::<&str>)?,
&IconMenuItem::new(handle, "IconMenuItem 1", true, Some(icon1), None::<&str>)?,
])
.separator()
.cut()
.copy()
.paste()
.separator()
.text("item2", "MenuItem 2")
.check("checkitem2", "CheckMenuItem 2")
.icon("iconitem2", "IconMenuItem 2", app.default_window_icon().cloned().unwrap())
.build()?;
app.set_menu(menu);
Ok(())
});Implementations§
Source§impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M>
impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M>
Source§impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M>
impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M>
Sourcepub fn item(self, item: &dyn IsMenuItem<R>) -> Self
pub fn item(self, item: &dyn IsMenuItem<R>) -> Self
Add this item to the menu.
Sourcepub fn items(self, items: &[&dyn IsMenuItem<R>]) -> Self
pub fn items(self, items: &[&dyn IsMenuItem<R>]) -> Self
Add these items to the menu.
Sourcepub fn text<I: Into<MenuId>, S: AsRef<str>>(self, id: I, text: S) -> Self
pub fn text<I: Into<MenuId>, S: AsRef<str>>(self, id: I, text: S) -> Self
Add a MenuItem to the menu.
Sourcepub fn check<I: Into<MenuId>, S: AsRef<str>>(self, id: I, text: S) -> Self
pub fn check<I: Into<MenuId>, S: AsRef<str>>(self, id: I, text: S) -> Self
Add a CheckMenuItem to the menu.
Sourcepub fn icon<I: Into<MenuId>, S: AsRef<str>>(
self,
id: I,
text: S,
icon: Image<'_>,
) -> Self
pub fn icon<I: Into<MenuId>, S: AsRef<str>>( self, id: I, text: S, icon: Image<'_>, ) -> Self
Add an IconMenuItem to the menu.
Sourcepub fn native_icon<I: Into<MenuId>, S: AsRef<str>>(
self,
id: I,
text: S,
icon: NativeIcon,
) -> Self
pub fn native_icon<I: Into<MenuId>, S: AsRef<str>>( self, id: I, text: S, icon: NativeIcon, ) -> Self
Add an IconMenuItem with a native icon to the menu.
§Platform-specific:
- Windows / Linux: Unsupported.
Sourcepub fn copy_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn copy_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Copy menu item with specified text to the menu.
Sourcepub fn cut_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn cut_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Cut menu item with specified text to the menu.
Sourcepub fn paste_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn paste_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Paste menu item with specified text to the menu.
Sourcepub fn select_all(self) -> Self
pub fn select_all(self) -> Self
Add SelectAll menu item to the menu.
Sourcepub fn select_all_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn select_all_with_text<S: AsRef<str>>(self, text: S) -> Self
Add SelectAll menu item with specified text to the menu.
Sourcepub fn undo_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn undo_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Undo menu item with specified text to the menu.
§Platform-specific:
- Windows / Linux: Unsupported.
Sourcepub fn redo_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn redo_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Redo menu item with specified text to the menu.
§Platform-specific:
- Windows / Linux: Unsupported.
Sourcepub fn minimize_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn minimize_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Minimize window menu item with specified text to the menu.
§Platform-specific:
- Linux: Unsupported.
Sourcepub fn maximize_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn maximize_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Maximize window menu item with specified text to the menu.
§Platform-specific:
- Linux: Unsupported.
Sourcepub fn fullscreen(self) -> Self
pub fn fullscreen(self) -> Self
Sourcepub fn fullscreen_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn fullscreen_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Fullscreen menu item with specified text to the menu.
§Platform-specific:
- Windows / Linux: Unsupported.
Sourcepub fn hide_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn hide_with_text<S: AsRef<str>>(self, text: S) -> Self
Sourcepub fn hide_others(self) -> Self
pub fn hide_others(self) -> Self
Sourcepub fn hide_others_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn hide_others_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Hide other windows menu item with specified text to the menu.
§Platform-specific:
- Linux: Unsupported.
Sourcepub fn show_all_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn show_all_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Show all app windows menu item with specified text to the menu.
§Platform-specific:
- Windows / Linux: Unsupported.
Sourcepub fn close_window(self) -> Self
pub fn close_window(self) -> Self
Sourcepub fn close_window_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn close_window_with_text<S: AsRef<str>>(self, text: S) -> Self
Sourcepub fn quit_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn quit_with_text<S: AsRef<str>>(self, text: S) -> Self
Sourcepub fn about(self, metadata: Option<AboutMetadata<'_>>) -> Self
pub fn about(self, metadata: Option<AboutMetadata<'_>>) -> Self
Add About app menu item to the menu.
Sourcepub fn about_with_text<S: AsRef<str>>(
self,
text: S,
metadata: Option<AboutMetadata<'_>>,
) -> Self
pub fn about_with_text<S: AsRef<str>>( self, text: S, metadata: Option<AboutMetadata<'_>>, ) -> Self
Add About app menu item with specified text to the menu.
Sourcepub fn services_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn services_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Services menu item with specified text to the menu.
§Platform-specific:
- Windows / Linux: Unsupported.
Sourcepub fn bring_all_to_front(self) -> Self
pub fn bring_all_to_front(self) -> Self
Sourcepub fn bring_all_to_front_with_text<S: AsRef<str>>(self, text: S) -> Self
pub fn bring_all_to_front_with_text<S: AsRef<str>>(self, text: S) -> Self
Add Bring All to Front menu item with specified text to the menu.
§Platform-specific:
- Windows / Linux: Unsupported.