Skip to main content

MenuBuilder

Struct MenuBuilder 

Source
pub struct MenuBuilder<'m, R: Runtime, M: Manager<R>> { /* private fields */ }
Available on desktop only.
Expand description

A builder type for Menu

§Platform-specific:

§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>

Source

pub fn new(manager: &'m M) -> Self

Create a new menu builder.

Source

pub fn with_id<I: Into<MenuId>>(manager: &'m M, id: I) -> Self

Create a new menu builder with the specified id.

Source

pub fn build(self) -> Result<Menu<R>>

Builds this menu

Source§

impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M>

Source

pub fn id<I: Into<MenuId>>(self, id: I) -> Self

Set the id for this menu.

Source

pub fn item(self, item: &dyn IsMenuItem<R>) -> Self

Add this item to the menu.

Source

pub fn items(self, items: &[&dyn IsMenuItem<R>]) -> Self

Add these items to the menu.

Source

pub fn text<I: Into<MenuId>, S: AsRef<str>>(self, id: I, text: S) -> Self

Add a MenuItem to the menu.

Source

pub fn check<I: Into<MenuId>, S: AsRef<str>>(self, id: I, text: S) -> Self

Add a CheckMenuItem to the menu.

Source

pub fn icon<I: Into<MenuId>, S: AsRef<str>>( self, id: I, text: S, icon: Image<'_>, ) -> Self

Add an IconMenuItem to the menu.

Source

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.
Source

pub fn separator(self) -> Self

Add Separator menu item to the menu.

Source

pub fn copy(self) -> Self

Add Copy menu item to the menu.

Source

pub fn copy_with_text<S: AsRef<str>>(self, text: S) -> Self

Add Copy menu item with specified text to the menu.

Source

pub fn cut(self) -> Self

Add Cut menu item to the menu.

Source

pub fn cut_with_text<S: AsRef<str>>(self, text: S) -> Self

Add Cut menu item with specified text to the menu.

Source

pub fn paste(self) -> Self

Add Paste menu item to the menu.

Source

pub fn paste_with_text<S: AsRef<str>>(self, text: S) -> Self

Add Paste menu item with specified text to the menu.

Source

pub fn select_all(self) -> Self

Add SelectAll menu item to the menu.

Source

pub fn select_all_with_text<S: AsRef<str>>(self, text: S) -> Self

Add SelectAll menu item with specified text to the menu.

Source

pub fn undo(self) -> Self

Add Undo menu item to the menu.

§Platform-specific:
  • Windows / Linux: Unsupported.
Source

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.
Source

pub fn redo(self) -> Self

Add Redo menu item to the menu.

§Platform-specific:
  • Windows / Linux: Unsupported.
Source

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.
Source

pub fn minimize(self) -> Self

Add Minimize window menu item to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

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.
Source

pub fn maximize(self) -> Self

Add Maximize window menu item to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

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.
Source

pub fn fullscreen(self) -> Self

Add Fullscreen menu item to the menu.

§Platform-specific:
  • Windows / Linux: Unsupported.
Source

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.
Source

pub fn hide(self) -> Self

Add Hide window menu item to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

pub fn hide_with_text<S: AsRef<str>>(self, text: S) -> Self

Add Hide window menu item with specified text to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

pub fn hide_others(self) -> Self

Add Hide other windows menu item to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

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.
Source

pub fn show_all(self) -> Self

Add Show all app windows menu item to the menu.

§Platform-specific:
  • Windows / Linux: Unsupported.
Source

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.
Source

pub fn close_window(self) -> Self

Add Close window menu item to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

pub fn close_window_with_text<S: AsRef<str>>(self, text: S) -> Self

Add Close window menu item with specified text to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

pub fn quit(self) -> Self

Add Quit app menu item to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

pub fn quit_with_text<S: AsRef<str>>(self, text: S) -> Self

Add Quit app menu item with specified text to the menu.

§Platform-specific:
  • Linux: Unsupported.
Source

pub fn about(self, metadata: Option<AboutMetadata<'_>>) -> Self

Add About app menu item to the menu.

Source

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.

Source

pub fn services(self) -> Self

Add Services menu item to the menu.

§Platform-specific:
  • Windows / Linux: Unsupported.
Source

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.
Source

pub fn bring_all_to_front(self) -> Self

Add Bring All to Front menu item to the menu.

§Platform-specific:
  • Windows / Linux: Unsupported.
Source

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.

Auto Trait Implementations§

§

impl<'m, R, M> Freeze for MenuBuilder<'m, R, M>

§

impl<'m, R, M> !RefUnwindSafe for MenuBuilder<'m, R, M>

§

impl<'m, R, M> Send for MenuBuilder<'m, R, M>
where M: Sync,

§

impl<'m, R, M> Sync for MenuBuilder<'m, R, M>
where M: Sync,

§

impl<'m, R, M> Unpin for MenuBuilder<'m, R, M>

§

impl<'m, R, M> UnsafeUnpin for MenuBuilder<'m, R, M>

§

impl<'m, R, M> !UnwindSafe for MenuBuilder<'m, R, M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T