Struct tauri::menu::Menu

source ·
pub struct Menu<R: Runtime>(/* private fields */);
Available on desktop only.
Expand description

A type that is either a menu bar on the window on Windows and Linux or as a global menu in the menubar on macOS.

Implementations§

source§

impl<R: Runtime> Menu<R>

source

pub fn new<M: Manager<R>>(manager: &M) -> Result<Self>

Creates a new menu.

source

pub fn with_id<M: Manager<R>, I: Into<MenuId>>( manager: &M, id: I ) -> Result<Self>

Creates a new menu with the specified id.

source

pub fn with_items<M: Manager<R>>( manager: &M, items: &[&dyn IsMenuItem<R>] ) -> Result<Self>

Creates a new menu with given items. It calls Menu::new and Menu::append_items internally.

source

pub fn with_id_and_items<M: Manager<R>, I: Into<MenuId>>( manager: &M, id: I, items: &[&dyn IsMenuItem<R>] ) -> Result<Self>

Creates a new menu with the specified id and given items. It calls Menu::new and Menu::append_items internally.

source

pub fn default(app_handle: &AppHandle<R>) -> Result<Self>

Creates a menu filled with default menu items and submenus.

source

pub fn app_handle(&self) -> &AppHandle<R>

The application handle associated with this type.

source

pub fn id(&self) -> &MenuId

Returns a unique identifier associated with this menu.

source

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

Add a menu item to the end of this menu.

§Platform-specific:
  • macOS: Only Submenu can be added to the menu.
source

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

Add menu items to the end of this menu. It calls Menu::append in a loop internally.

§Platform-specific:
  • macOS: Only Submenu can be added to the menu
source

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

Add a menu item to the beginning of this menu.

§Platform-specific:
  • macOS: Only Submenu can be added to the menu
source

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

Add menu items to the beginning of this menu. It calls Menu::insert_items with position of 0 internally.

§Platform-specific:
  • macOS: Only Submenu can be added to the menu
source

pub fn insert(&self, item: &dyn IsMenuItem<R>, position: usize) -> Result<()>

Insert a menu item at the specified position in the menu.

§Platform-specific:
  • macOS: Only Submenu can be added to the menu
source

pub fn insert_items( &self, items: &[&dyn IsMenuItem<R>], position: usize ) -> Result<()>

Insert menu items at the specified position in the menu.

§Platform-specific:
  • macOS: Only Submenu can be added to the menu
source

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

Remove a menu item from this menu.

source

pub fn remove_at(&self, position: usize) -> Result<Option<MenuItemKind<R>>>

Remove the menu item at the specified position from this menu and returns it.

source

pub fn get<'a, I>(&self, id: &'a I) -> Option<MenuItemKind<R>>
where I: ?Sized, MenuId: PartialEq<&'a I>,

Retrieves the menu item matching the given identifier.

source

pub fn items(&self) -> Result<Vec<MenuItemKind<R>>>

Returns a list of menu items that has been added to this menu.

source

pub fn set_as_app_menu(&self) -> Result<Option<Menu<R>>>

Set this menu as the application menu.

This is an alias for AppHandle::set_menu.

source

pub fn set_as_window_menu(&self, window: &Window<R>) -> Result<Option<Menu<R>>>

Set this menu as the window menu.

This is an alias for Window::set_menu.

Trait Implementations§

source§

impl<R: Runtime> Clone for Menu<R>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<R: Runtime> ContextMenu for Menu<R>

source§

fn popup<T: Runtime>(&self, window: Window<T>) -> Result<()>

Popup this menu as a context menu on the specified window at the cursor position.
source§

fn popup_at<T: Runtime, P: Into<Position>>( &self, window: Window<T>, position: P ) -> Result<()>

Popup this menu as a context menu on the specified window at the specified position. Read more
source§

impl<R: Runtime> Resource for Menu<R>

source§

fn name(&self) -> Cow<'_, str>

Returns a string representation of the resource. The default implementation returns the Rust type name, but specific resource types may override this trait method.
source§

fn close(self: Arc<Self>)

Resources may implement the close() trait method if they need to do resource specific clean-ups, such as cancelling pending futures, after a resource has been removed from the resource table.

Auto Trait Implementations§

§

impl<R> Freeze for Menu<R>

§

impl<R> !RefUnwindSafe for Menu<R>

§

impl<R> Send for Menu<R>

§

impl<R> Sync for Menu<R>

§

impl<R> Unpin for Menu<R>

§

impl<R> !UnwindSafe for Menu<R>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.