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<Menu, Error>
pub fn with_items(items: &[&dyn IsMenuItem]) -> Result<Menu, Error>
Creates a new menu with given items. It calls Menu::new and Menu::append_items internally.
Sourcepub fn with_id_and_items<I>(
id: I,
items: &[&dyn IsMenuItem],
) -> Result<Menu, Error>
pub fn with_id_and_items<I>( id: I, items: &[&dyn IsMenuItem], ) -> Result<Menu, Error>
Creates a new menu with the specified id and given items. It calls Menu::new and Menu::append_items internally.
Sourcepub fn append_items(&self, items: &[&dyn IsMenuItem]) -> Result<(), Error>
pub fn append_items(&self, items: &[&dyn IsMenuItem]) -> Result<(), Error>
Add menu items to the end of this menu. It calls Menu::append in a loop internally.
§Platform-spcific:
- macOS: Only
Submenucan be added to the menu
Sourcepub fn prepend_items(&self, items: &[&dyn IsMenuItem]) -> Result<(), Error>
pub fn prepend_items(&self, items: &[&dyn IsMenuItem]) -> Result<(), Error>
Add menu items to the beginning of this menu. It calls Menu::insert_items with position of 0 internally.
§Platform-spcific:
- macOS: Only
Submenucan be added to the menu
Sourcepub fn insert_items(
&self,
items: &[&dyn IsMenuItem],
position: usize,
) -> Result<(), Error>
pub fn insert_items( &self, items: &[&dyn IsMenuItem], position: usize, ) -> Result<(), Error>
Sourcepub fn remove(&self, item: &dyn IsMenuItem) -> Result<(), Error>
pub fn remove(&self, item: &dyn IsMenuItem) -> Result<(), Error>
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 fn init_for_gtk_window<W, C>(
&self,
window: &W,
container: Option<&C>,
) -> Result<(), Error>
Available on Linux and crate feature gtk only.
pub fn init_for_gtk_window<W, C>( &self, window: &W, container: Option<&C>, ) -> Result<(), Error>
gtk only.Adds this menu to a gtk::Window
container: this is an optional paramter to specify a container for thegtk::MenuBar, it is highly recommended to pass a container, otherwise the menubar will be added directly to the window, which is usually not the desired behavior. If using agtk::Boxas a container, it is added usingBox::pack_start(menubar, false, false, 0)then reordered to be the first child ofgtk::BoxusingBox::reorder_child(menubar, 0).
§Example:
let window = gtk::Window::builder().build();
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
let menu = muda::Menu::new();
// -- snip, add your menu items --
menu.init_for_gtk_window(&window, Some(&vbox));
// then proceed to add your widgets to the `vbox`§Panics:
Panics if the gtk event loop hasn’t been initialized on the thread.
Sourcepub fn remove_for_gtk_window<W>(&self, window: &W) -> Result<(), Error>
Available on Linux and crate feature gtk only.
pub fn remove_for_gtk_window<W>(&self, window: &W) -> Result<(), Error>
gtk only.Removes this menu from a gtk::Window
Sourcepub fn hide_for_gtk_window<W>(&self, window: &W) -> Result<(), Error>
Available on Linux and crate feature gtk only.
pub fn hide_for_gtk_window<W>(&self, window: &W) -> Result<(), Error>
gtk only.Hides this menu from a gtk::Window
Sourcepub fn show_for_gtk_window<W>(&self, window: &W) -> Result<(), Error>
Available on Linux and crate feature gtk only.
pub fn show_for_gtk_window<W>(&self, window: &W) -> Result<(), Error>
gtk only.Shows this menu on a gtk::Window
Sourcepub fn is_visible_on_gtk_window<W>(&self, window: &W) -> bool
Available on Linux and crate feature gtk only.
pub fn is_visible_on_gtk_window<W>(&self, window: &W) -> bool
gtk only.Returns whether this menu visible on a gtk::Window
Available on Linux and crate feature gtk only.
gtk only.Returns the gtk::MenuBar that is associated with this window if it exists.
This is useful to get information about the menubar for example its height.
Trait Implementations§
Source§impl ContextMenu for Menu
impl ContextMenu for Menu
gtk only.gtk::Window Read moregtk only.Menu, and returns None if it wasn’t.Menu, and panics if it wasn’t.Submenu, and returns None if it wasn’t.Submenu, and panics if it wasn’t.Auto Trait Implementations§
impl Freeze for Menu
impl !RefUnwindSafe for Menu
impl !Send for Menu
impl !Sync for Menu
impl Unpin for Menu
impl !UnwindSafe for Menu
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.