2022-05-09 03:36:39 +10:00
|
|
|
//! muda is a Menu Utilities library for Desktop Applications.
|
2022-05-07 06:57:58 +10:00
|
|
|
//! # Creating root menus
|
|
|
|
//!
|
|
|
|
//! Before you can add submenus and menu items, you first need a root or a base menu.
|
|
|
|
//! ```no_run
|
2022-07-20 22:34:09 +10:00
|
|
|
//! let mut menu = muda::Menu::new();
|
2022-05-07 06:57:58 +10:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! # Adding submens to the root menu
|
|
|
|
//!
|
|
|
|
//! Once you have a root menu you can start adding [`Submenu`]s by using [`Menu::add_submenu`].
|
|
|
|
//! ```no_run
|
2022-07-20 22:34:09 +10:00
|
|
|
//! let mut menu = muda::Menu::new();
|
2022-05-07 06:57:58 +10:00
|
|
|
//! let file_menu = menu.add_submenu("File", true);
|
|
|
|
//! let edit_menu = menu.add_submenu("Edit", true);
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! # Aadding menu items and submenus within another submenu
|
|
|
|
//!
|
2022-06-14 22:00:00 +10:00
|
|
|
//! Once you have a [`Submenu`] you can star creating more [`Submenu`]s or [`MenuItem`]s.
|
2022-05-07 06:57:58 +10:00
|
|
|
//! ```no_run
|
2022-07-20 22:34:09 +10:00
|
|
|
//! let mut menu = muda::Menu::new();
|
2022-05-07 06:57:58 +10:00
|
|
|
//!
|
2022-07-20 22:34:09 +10:00
|
|
|
//! let mut file_menu = menu.add_submenu("File", true);
|
|
|
|
//! let open_item = file_menu.add_item("Open", true, None);
|
|
|
|
//! let save_item = file_menu.add_item("Save", true, None);
|
2022-05-07 06:57:58 +10:00
|
|
|
//!
|
2022-07-20 22:34:09 +10:00
|
|
|
//! let mut edit_menu = menu.add_submenu("Edit", true);
|
|
|
|
//! let copy_item = file_menu.add_item("Copy", true, None);
|
|
|
|
//! let cut_item = file_menu.add_item("Cut", true, None);
|
2022-05-07 06:57:58 +10:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! # Add your root menu to a Window (Windows and Linux Only)
|
|
|
|
//!
|
|
|
|
//! You can use [`Menu`] to display a top menu in a Window on Windows and Linux.
|
2022-07-20 22:34:09 +10:00
|
|
|
//! ```ignore
|
|
|
|
//! let mut menu = muda::Menu::new();
|
2022-05-07 06:57:58 +10:00
|
|
|
//! // --snip--
|
|
|
|
//! #[cfg(target_os = "windows")]
|
|
|
|
//! menu.init_for_hwnd(window.hwnd() as isize);
|
|
|
|
//! #[cfg(target_os = "linux")]
|
|
|
|
//! menu.init_for_gtk_window(>k_window);
|
2022-05-08 16:32:31 +10:00
|
|
|
//! #[cfg(target_os = "macos")]
|
|
|
|
//! menu.init_for_nsapp();
|
2022-05-07 06:57:58 +10:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! # Processing menu events
|
|
|
|
//!
|
|
|
|
//! You can use [`menu_event_receiver`] to get a reference to the [`MenuEventReceiver`]
|
|
|
|
//! which you can use to listen to events when a menu item is activated
|
2022-07-20 22:34:09 +10:00
|
|
|
//! ```ignore
|
|
|
|
//! if let Ok(event) = muda::menu_event_receiver().try_recv() {
|
2022-05-07 06:57:58 +10:00
|
|
|
//! match event.id {
|
|
|
|
//! _ if event.id == save_item.id() => {
|
|
|
|
//! println!("Save menu item activated");
|
|
|
|
//! },
|
|
|
|
//! _ => {}
|
|
|
|
//! }
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
|
2022-07-20 22:34:09 +10:00
|
|
|
use accelerator::Accelerator;
|
2022-05-07 00:25:45 +10:00
|
|
|
use crossbeam_channel::{unbounded, Receiver, Sender};
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
2022-07-20 22:34:09 +10:00
|
|
|
pub mod accelerator;
|
2022-06-07 21:05:20 +10:00
|
|
|
mod counter;
|
2022-05-05 21:50:22 +10:00
|
|
|
mod platform_impl;
|
|
|
|
|
2022-05-07 00:25:45 +10:00
|
|
|
static MENU_CHANNEL: Lazy<(Sender<MenuEvent>, Receiver<MenuEvent>)> = Lazy::new(|| unbounded());
|
|
|
|
|
2022-06-14 22:00:00 +10:00
|
|
|
/// Gets a reference to the event channel's [Receiver<MenuEvent>]
|
2022-05-07 06:57:58 +10:00
|
|
|
/// which can be used to listen for menu events.
|
2022-06-14 22:00:00 +10:00
|
|
|
pub fn menu_event_receiver<'a>() -> &'a Receiver<MenuEvent> {
|
2022-05-07 00:25:45 +10:00
|
|
|
&MENU_CHANNEL.1
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Describes a menu event emitted when a menu item is activated
|
|
|
|
pub struct MenuEvent {
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Id of the menu item which triggered this event
|
2022-05-07 00:25:45 +10:00
|
|
|
pub id: u64,
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// This is the root menu type to which you can add
|
|
|
|
/// more submenus and later be add to the top of a window (on Windows and Linux)
|
|
|
|
/// or used as the menubar menu (on macOS) or displayed as a popup menu.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
2022-07-20 22:34:09 +10:00
|
|
|
/// ```no_run
|
|
|
|
/// let mut menu = muda::Menu::new();
|
2022-05-07 06:57:58 +10:00
|
|
|
/// let file_menu = menu.add_submenu("File", true);
|
|
|
|
/// let edit_menu = menu.add_submenu("Edit", true);
|
|
|
|
/// ```
|
2022-06-07 21:05:20 +10:00
|
|
|
#[derive(Clone)]
|
2022-05-05 21:50:22 +10:00
|
|
|
pub struct Menu(platform_impl::Menu);
|
|
|
|
|
|
|
|
impl Menu {
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Creates a new root menu.
|
2022-05-05 21:50:22 +10:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Self(platform_impl::Menu::new())
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Creates a new [`Submenu`] whithin this menu.
|
2022-06-07 21:05:20 +10:00
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 23:42:50 +10:00
|
|
|
/// - **Windows / Linux:** The menu label can contain `&` to indicate which letter should get a generated accelerator.
|
2022-06-07 21:05:20 +10:00
|
|
|
/// For example, using `&File` for the File menu would result in the label gets an underline under the `F`,
|
|
|
|
/// and the `&` character is not displayed on menu label.
|
|
|
|
/// Then the menu can be activated by press `Alt+F`.
|
2022-06-12 23:42:50 +10:00
|
|
|
pub fn add_submenu<S: AsRef<str>>(&mut self, label: S, enabled: bool) -> Submenu {
|
2022-05-05 21:50:22 +10:00
|
|
|
Submenu(self.0.add_submenu(label, enabled))
|
|
|
|
}
|
|
|
|
|
2022-06-10 22:09:56 +10:00
|
|
|
/// Adds this menu to a [`gtk::ApplicationWindow`]
|
2022-06-06 22:36:22 +10:00
|
|
|
///
|
|
|
|
/// This method adds a [`gtk::Box`] then adds a [`gtk::MenuBar`] as its first child and returns the [`gtk::Box`].
|
|
|
|
/// So if more widgets need to be added, then [`gtk::prelude::BoxExt::pack_start`] or
|
|
|
|
/// similiar methods should be used on the returned [`gtk::Box`].
|
|
|
|
///
|
|
|
|
/// ## Safety:
|
|
|
|
///
|
|
|
|
/// This should be called before anything is added to the window.
|
2022-06-08 02:32:10 +10:00
|
|
|
///
|
|
|
|
/// ## Panics:
|
|
|
|
///
|
|
|
|
/// Panics if the gtk event loop hasn't been initialized on the thread.
|
2022-05-05 21:50:22 +10:00
|
|
|
#[cfg(target_os = "linux")]
|
2022-06-06 22:36:22 +10:00
|
|
|
pub fn init_for_gtk_window<W>(&self, w: &W) -> std::rc::Rc<gtk::Box>
|
2022-05-05 21:50:22 +10:00
|
|
|
where
|
2022-06-10 22:09:56 +10:00
|
|
|
W: gtk::prelude::IsA<gtk::ApplicationWindow>,
|
2022-05-05 21:50:22 +10:00
|
|
|
W: gtk::prelude::IsA<gtk::Container>,
|
2022-06-07 21:05:20 +10:00
|
|
|
W: gtk::prelude::IsA<gtk::Window>,
|
2022-05-05 21:50:22 +10:00
|
|
|
{
|
|
|
|
self.0.init_for_gtk_window(w)
|
|
|
|
}
|
2022-05-07 02:38:39 +10:00
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Adds this menu to a win32 window.
|
2022-06-07 21:05:20 +10:00
|
|
|
///
|
|
|
|
/// ## Note about accelerators:
|
|
|
|
///
|
|
|
|
/// For accelerators to work, the event loop needs to call
|
|
|
|
/// [`TranslateAcceleratorW`](windows_sys::Win32::UI::WindowsAndMessaging::TranslateAcceleratorW)
|
|
|
|
/// with the [`HACCEL`](windows_sys::Win32::UI::WindowsAndMessaging::HACCEL) returned from [`Menu::haccel`]
|
|
|
|
///
|
|
|
|
/// #### Example:
|
|
|
|
/// ```
|
|
|
|
/// # use windows_sys::Win32::UI::WindowsAndMessaging::{MSG, GetMessageW, TranslateMessage, DispatchMessageW };
|
|
|
|
/// let menu = Menu::new();
|
|
|
|
/// unsafe {
|
|
|
|
/// let msg: MSG = std::mem::zeroed();
|
|
|
|
/// while GetMessageW(&mut msg, 0, 0, 0) == 1 {
|
|
|
|
/// let translated = TranslateAcceleratorW(msg.hwnd, menu.haccel(), msg);
|
|
|
|
/// if !translated {
|
|
|
|
/// TranslateMessage(&msg);
|
|
|
|
/// DispatchMessageW(&msg);
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
2022-05-07 02:38:39 +10:00
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
pub fn init_for_hwnd(&self, hwnd: isize) {
|
|
|
|
self.0.init_for_hwnd(hwnd)
|
|
|
|
}
|
2022-05-08 16:32:31 +10:00
|
|
|
|
2022-06-07 21:05:20 +10:00
|
|
|
/// Returns The [`HACCEL`](windows_sys::Win32::UI::WindowsAndMessaging::HACCEL) associated with this menu
|
|
|
|
/// It can be used with [`TranslateAcceleratorW`](windows_sys::Win32::UI::WindowsAndMessaging::TranslateAcceleratorW)
|
|
|
|
/// in the event loop to enable accelerators
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
pub fn haccel(&self) -> windows_sys::Win32::UI::WindowsAndMessaging::HACCEL {
|
|
|
|
self.0.haccel()
|
|
|
|
}
|
|
|
|
|
2022-06-10 22:09:56 +10:00
|
|
|
/// Removes this menu from a [`gtk::ApplicationWindow`]
|
2022-06-08 02:32:10 +10:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
pub fn remove_for_gtk_window<W>(&self, w: &W)
|
|
|
|
where
|
2022-06-10 22:09:56 +10:00
|
|
|
W: gtk::prelude::IsA<gtk::ApplicationWindow>,
|
2022-06-08 02:32:10 +10:00
|
|
|
W: gtk::prelude::IsA<gtk::Window>,
|
|
|
|
{
|
|
|
|
self.0.remove_for_gtk_window(w)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Removes this menu from a win32 window
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
pub fn remove_for_hwnd(&self, hwnd: isize) {
|
|
|
|
self.0.remove_for_hwnd(hwnd)
|
|
|
|
}
|
|
|
|
|
2022-06-10 22:09:56 +10:00
|
|
|
/// Hides this menu from a [`gtk::ApplicationWindow`]
|
2022-06-08 02:32:10 +10:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
pub fn hide_for_gtk_window<W>(&self, w: &W)
|
|
|
|
where
|
2022-06-10 22:09:56 +10:00
|
|
|
W: gtk::prelude::IsA<gtk::ApplicationWindow>,
|
2022-06-08 02:32:10 +10:00
|
|
|
{
|
|
|
|
self.0.hide_for_gtk_window(w)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Hides this menu from a win32 window
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
pub fn hide_for_hwnd(&self, hwnd: isize) {
|
|
|
|
self.0.hide_for_hwnd(hwnd)
|
|
|
|
}
|
|
|
|
|
2022-06-10 22:09:56 +10:00
|
|
|
/// Shows this menu from a [`gtk::ApplicationWindow`]
|
2022-06-08 02:32:10 +10:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
pub fn show_for_gtk_window<W>(&self, w: &W)
|
|
|
|
where
|
2022-06-10 22:09:56 +10:00
|
|
|
W: gtk::prelude::IsA<gtk::ApplicationWindow>,
|
2022-06-08 02:32:10 +10:00
|
|
|
{
|
|
|
|
self.0.show_for_gtk_window(w)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Shows this menu from a win32 window
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
pub fn show_for_hwnd(&self, hwnd: isize) {
|
|
|
|
self.0.show_for_hwnd(hwnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Adds this menu to an NSApp.
|
2022-05-08 16:32:31 +10:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
pub fn init_for_nsapp(&self) {
|
|
|
|
self.0.init_for_nsapp()
|
|
|
|
}
|
2022-06-08 02:32:10 +10:00
|
|
|
|
|
|
|
/// Removes this menu from an NSApp.
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
pub fn remove_for_nsapp(&self) {
|
|
|
|
self.0.remove_for_nsapp()
|
|
|
|
}
|
2022-05-05 21:50:22 +10:00
|
|
|
}
|
|
|
|
|
2022-06-12 23:42:50 +10:00
|
|
|
/// This is a Submenu within another [`Submenu`] or [`Menu`].
|
2022-06-07 21:05:20 +10:00
|
|
|
#[derive(Clone)]
|
2022-05-05 21:50:22 +10:00
|
|
|
pub struct Submenu(platform_impl::Submenu);
|
|
|
|
|
|
|
|
impl Submenu {
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Gets the submenus's current label.
|
2022-05-07 01:18:34 +10:00
|
|
|
pub fn label(&self) -> String {
|
|
|
|
self.0.label()
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Sets a new label for the submenu.
|
2022-06-12 23:42:50 +10:00
|
|
|
pub fn set_label<S: AsRef<str>>(&mut self, label: S) {
|
2022-05-05 21:50:22 +10:00
|
|
|
self.0.set_label(label)
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Gets the submenu's current state, whether enabled or not.
|
2022-05-07 01:18:34 +10:00
|
|
|
pub fn enabled(&self) -> bool {
|
|
|
|
self.0.enabled()
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Enables or disables the submenu
|
2022-05-05 21:50:22 +10:00
|
|
|
pub fn set_enabled(&mut self, enabled: bool) {
|
|
|
|
self.0.set_enabled(enabled)
|
|
|
|
}
|
2022-05-07 06:57:58 +10:00
|
|
|
|
|
|
|
/// Creates a new [`Submenu`] whithin this submenu.
|
2022-06-07 21:05:20 +10:00
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 23:42:50 +10:00
|
|
|
/// - **Windows / Linux:** The menu label can contain `&` to indicate which letter should get a generated accelerator.
|
2022-06-07 21:05:20 +10:00
|
|
|
/// For example, using `&File` for the File menu would result in the label gets an underline under the `F`,
|
|
|
|
/// and the `&` character is not displayed on menu label.
|
|
|
|
/// Then the menu can be activated by press `F` when its parent menu is active.
|
2022-06-12 23:42:50 +10:00
|
|
|
pub fn add_submenu<S: AsRef<str>>(&mut self, label: S, enabled: bool) -> Submenu {
|
2022-05-05 21:50:22 +10:00
|
|
|
Submenu(self.0.add_submenu(label, enabled))
|
|
|
|
}
|
|
|
|
|
2022-06-14 22:00:00 +10:00
|
|
|
/// Creates a new [`MenuItem`] whithin this submenu.
|
2022-06-07 21:05:20 +10:00
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 23:42:50 +10:00
|
|
|
/// - **Windows / Linux:** The menu item label can contain `&` to indicate which letter should get a generated accelerator.
|
2022-06-07 21:05:20 +10:00
|
|
|
/// For example, using `&Save` for the save menu item would result in the label gets an underline under the `S`,
|
|
|
|
/// and the `&` character is not displayed on menu item label.
|
|
|
|
/// Then the menu item can be activated by press `S` when its parent menu is active.
|
2022-06-14 22:00:00 +10:00
|
|
|
pub fn add_item<S: AsRef<str>>(
|
2022-06-07 21:05:20 +10:00
|
|
|
&mut self,
|
2022-06-12 23:42:50 +10:00
|
|
|
label: S,
|
2022-06-07 21:05:20 +10:00
|
|
|
enabled: bool,
|
2022-07-20 22:34:09 +10:00
|
|
|
accelerator: Option<Accelerator>,
|
2022-06-14 22:00:00 +10:00
|
|
|
) -> MenuItem {
|
|
|
|
MenuItem(self.0.add_item(label, enabled, accelerator))
|
2022-05-05 21:50:22 +10:00
|
|
|
}
|
2022-06-10 22:09:56 +10:00
|
|
|
|
2022-06-12 23:42:50 +10:00
|
|
|
/// Creates a new [`NativeMenuItem`] within this submenu.
|
2022-06-10 22:09:56 +10:00
|
|
|
pub fn add_native_item(&mut self, item: NativeMenuItem) {
|
|
|
|
self.0.add_native_item(item)
|
|
|
|
}
|
2022-06-12 23:42:50 +10:00
|
|
|
|
|
|
|
/// Creates a new [`CheckMenuItem`] within this submenu.
|
|
|
|
pub fn add_check_item<S: AsRef<str>>(
|
|
|
|
&mut self,
|
|
|
|
label: S,
|
|
|
|
enabled: bool,
|
|
|
|
checked: bool,
|
2022-07-20 22:34:09 +10:00
|
|
|
accelerator: Option<Accelerator>,
|
2022-06-12 23:42:50 +10:00
|
|
|
) -> CheckMenuItem {
|
|
|
|
CheckMenuItem(self.0.add_check_item(label, enabled, checked, accelerator))
|
|
|
|
}
|
2022-05-05 21:50:22 +10:00
|
|
|
}
|
|
|
|
|
2022-06-14 22:00:00 +10:00
|
|
|
/// This is a normal menu item within a [`Submenu`].
|
2022-05-05 21:50:22 +10:00
|
|
|
#[derive(Clone)]
|
2022-06-14 22:00:00 +10:00
|
|
|
pub struct MenuItem(platform_impl::MenuItem);
|
2022-05-05 21:50:22 +10:00
|
|
|
|
2022-06-14 22:00:00 +10:00
|
|
|
impl MenuItem {
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Gets the menu item's current label.
|
2022-05-07 01:18:34 +10:00
|
|
|
pub fn label(&self) -> String {
|
|
|
|
self.0.label()
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Sets a new label for the menu item.
|
2022-06-12 23:42:50 +10:00
|
|
|
pub fn set_label<S: AsRef<str>>(&mut self, label: S) {
|
2022-05-05 21:50:22 +10:00
|
|
|
self.0.set_label(label)
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Gets the menu item's current state, whether enabled or not.
|
2022-05-07 01:18:34 +10:00
|
|
|
pub fn enabled(&self) -> bool {
|
|
|
|
self.0.enabled()
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Enables or disables the menu item.
|
2022-05-05 21:50:22 +10:00
|
|
|
pub fn set_enabled(&mut self, enabled: bool) {
|
|
|
|
self.0.set_enabled(enabled)
|
|
|
|
}
|
|
|
|
|
2022-05-07 06:57:58 +10:00
|
|
|
/// Gets the unique id for this menu item.
|
2022-05-05 21:50:22 +10:00
|
|
|
pub fn id(&self) -> u64 {
|
|
|
|
self.0.id()
|
|
|
|
}
|
|
|
|
}
|
2022-06-10 22:09:56 +10:00
|
|
|
|
2022-06-14 22:00:00 +10:00
|
|
|
/// This is a menu item with a checkmark icon within a [`Submenu`].
|
2022-06-12 23:42:50 +10:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct CheckMenuItem(platform_impl::CheckMenuItem);
|
|
|
|
|
|
|
|
impl CheckMenuItem {
|
|
|
|
/// Gets the menu item's current label.
|
|
|
|
pub fn label(&self) -> String {
|
|
|
|
self.0.label()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets a new label for the menu item.
|
|
|
|
pub fn set_label<S: AsRef<str>>(&mut self, label: S) {
|
|
|
|
self.0.set_label(label)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the menu item's current state, whether enabled or not.
|
|
|
|
pub fn enabled(&self) -> bool {
|
|
|
|
self.0.enabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Enables or disables the menu item.
|
|
|
|
pub fn set_enabled(&mut self, enabled: bool) {
|
|
|
|
self.0.set_enabled(enabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the menu item's current state, whether checked or not.
|
|
|
|
pub fn checked(&self) -> bool {
|
|
|
|
self.0.checked()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Enables or disables the menu item.
|
|
|
|
pub fn set_checked(&mut self, checked: bool) {
|
|
|
|
self.0.set_checked(checked)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the unique id for this menu item.
|
|
|
|
pub fn id(&self) -> u64 {
|
|
|
|
self.0.id()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is a Native menu item within a [`Submenu`] with a predefined behavior.
|
2022-06-10 22:09:56 +10:00
|
|
|
#[non_exhaustive]
|
2022-06-11 22:35:33 +10:00
|
|
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
2022-06-10 22:09:56 +10:00
|
|
|
pub enum NativeMenuItem {
|
|
|
|
/// A native “About” menu item.
|
|
|
|
///
|
|
|
|
/// The first value is the application name, and the second is its metadata.
|
|
|
|
///
|
|
|
|
/// ## platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** the metadata is ignore.
|
2022-06-10 22:09:56 +10:00
|
|
|
About(String, AboutMetadata),
|
|
|
|
/// A native “hide the app” menu item.
|
|
|
|
///
|
|
|
|
/// ## platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-10 22:09:56 +10:00
|
|
|
Hide,
|
|
|
|
/// A native “hide all other windows" menu item.
|
|
|
|
///
|
|
|
|
/// ## platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-10 22:09:56 +10:00
|
|
|
HideOthers,
|
|
|
|
/// A native "Show all windows for this app" menu item.
|
|
|
|
///
|
|
|
|
/// ## platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-10 22:09:56 +10:00
|
|
|
ShowAll,
|
|
|
|
/// A native "Services" menu item.
|
|
|
|
///
|
|
|
|
/// ## platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-10 22:09:56 +10:00
|
|
|
Services,
|
|
|
|
/// A native "Close current window" menu item.
|
|
|
|
CloseWindow,
|
|
|
|
/// A native "Quit///
|
|
|
|
Quit,
|
|
|
|
/// A native "Copy" menu item.
|
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** macOS require this menu item to enable "Copy" keyboard shortcut for your app.
|
|
|
|
/// - **Linux Wayland:** Not implmeneted.
|
2022-06-10 22:09:56 +10:00
|
|
|
Copy,
|
|
|
|
/// A native "Cut" menu item.
|
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** macOS require this menu item to enable "Cut" keyboard shortcut for your app.
|
|
|
|
/// - **Linux Wayland:** Not implmeneted.
|
2022-06-10 22:09:56 +10:00
|
|
|
Cut,
|
|
|
|
/// A native "Paste" menu item.
|
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** macOS require this menu item to enable "Paste" keyboard shortcut for your app.
|
|
|
|
/// - **Linux Wayland:** Not implmeneted.
|
2022-06-10 22:09:56 +10:00
|
|
|
Paste,
|
|
|
|
/// A native "Undo" menu item.
|
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** macOS require this menu item to enable "Undo" keyboard shortcut for your app.
|
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-10 22:09:56 +10:00
|
|
|
Undo,
|
|
|
|
/// A native "Redo" menu item.
|
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** macOS require this menu item to enable "Redo" keyboard shortcut for your app.
|
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-10 22:09:56 +10:00
|
|
|
Redo,
|
|
|
|
/// A native "Select All" menu item.
|
|
|
|
///
|
|
|
|
/// ## Platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** macOS require this menu item to enable "Select All" keyboard shortcut for your app.
|
|
|
|
/// - **Linux Wayland:** Not implmeneted.
|
2022-06-10 22:09:56 +10:00
|
|
|
SelectAll,
|
2022-06-19 19:52:14 +10:00
|
|
|
/// A native "Toggle fullscreen" menu item.
|
2022-06-10 22:09:56 +10:00
|
|
|
///
|
|
|
|
/// ## platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-19 19:52:14 +10:00
|
|
|
ToggleFullScreen,
|
2022-06-10 22:09:56 +10:00
|
|
|
/// A native "Minimize current window" menu item.
|
|
|
|
Minimize,
|
|
|
|
/// A native "Zoom" menu item.
|
|
|
|
///
|
|
|
|
/// ## platform-specific:
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **Windows / Linux:** Unsupported.
|
2022-06-10 22:09:56 +10:00
|
|
|
Zoom,
|
|
|
|
/// Represends a Separator in the menu.
|
|
|
|
Separator,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Application metadata for the [`NativeMenuItem::About`].
|
|
|
|
///
|
|
|
|
/// ## Platform-specific
|
|
|
|
///
|
2022-06-12 02:17:39 +10:00
|
|
|
/// - **macOS:** The metadata is ignored.
|
2022-06-11 22:35:33 +10:00
|
|
|
#[derive(PartialEq, Eq, Debug, Clone, Default)]
|
2022-06-10 22:09:56 +10:00
|
|
|
pub struct AboutMetadata {
|
|
|
|
/// The application name.
|
|
|
|
pub version: Option<String>,
|
|
|
|
/// The authors of the application.
|
|
|
|
pub authors: Option<Vec<String>>,
|
|
|
|
/// Application comments.
|
|
|
|
pub comments: Option<String>,
|
|
|
|
/// The copyright of the application.
|
|
|
|
pub copyright: Option<String>,
|
|
|
|
/// The license of the application.
|
|
|
|
pub license: Option<String>,
|
|
|
|
/// The application website.
|
|
|
|
pub website: Option<String>,
|
|
|
|
/// The website label.
|
|
|
|
pub website_label: Option<String>,
|
|
|
|
}
|