@@ -186,6 +186,25 @@ impl Menu {
186186 Default :: default ( )
187187 }
188188
189+ /// Creates a new window menu with the given items.
190+ ///
191+ /// # Example
192+ /// ```
193+ /// # use tauri_runtime::menu::{Menu, MenuItem, CustomMenuItem, Submenu};
194+ /// Menu::with_items([
195+ /// MenuItem::SelectAll.into(),
196+ /// #[cfg(target_os = "macos")]
197+ /// MenuItem::Redo.into(),
198+ /// CustomMenuItem::new("toggle", "Toggle visibility").into(),
199+ /// Submenu::new("View", Menu::new()).into(),
200+ /// ]);
201+ /// ```
202+ pub fn with_items < I : IntoIterator < Item = MenuEntry > > ( items : I ) -> Self {
203+ Self {
204+ items : items. into_iter ( ) . collect ( ) ,
205+ }
206+ }
207+
189208 /// Adds the custom menu item to the menu.
190209 pub fn add_item ( mut self , item : CustomMenuItem ) -> Self {
191210 self . items . push ( MenuEntry :: CustomItem ( item) ) ;
@@ -349,6 +368,24 @@ pub enum MenuEntry {
349368 Submenu ( Submenu ) ,
350369}
351370
371+ impl From < CustomMenuItem > for MenuEntry {
372+ fn from ( item : CustomMenuItem ) -> Self {
373+ Self :: CustomItem ( item)
374+ }
375+ }
376+
377+ impl From < MenuItem > for MenuEntry {
378+ fn from ( item : MenuItem ) -> Self {
379+ Self :: NativeItem ( item)
380+ }
381+ }
382+
383+ impl From < Submenu > for MenuEntry {
384+ fn from ( submenu : Submenu ) -> Self {
385+ Self :: Submenu ( submenu)
386+ }
387+ }
388+
352389/// A menu item, bound to a pre-defined action or `Custom` emit an event. Note that status bar only
353390/// supports `Custom` menu item variants. And on the menu bar, some platforms might not support some
354391/// of the variants. Unsupported variant will be no-op on such platform.
0 commit comments