docs: add docs for PredefinedMenuItem (#51)

This commit is contained in:
Amr Bashir 2023-02-28 18:16:20 +02:00 committed by GitHub
parent 74801f238a
commit d2bd85bf7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
"muda": "patch"
---
Implement `PredefinedMenuItemm::maximize` and `PredefinedMenuItemm::hide` on Windows.

View file

@ -0,0 +1,5 @@
---
"muda": "patch"
---
Add docs for predefined menu items

View file

@ -30,8 +30,8 @@ use windows_sys::Win32::{
SetMenuItemInfoW, ShowWindow, TrackPopupMenu, HACCEL, HMENU, MB_ICONINFORMATION,
MENUITEMINFOW, MFS_CHECKED, MFS_DISABLED, MF_BYCOMMAND, MF_BYPOSITION, MF_CHECKED,
MF_DISABLED, MF_ENABLED, MF_GRAYED, MF_POPUP, MF_SEPARATOR, MF_STRING, MF_UNCHECKED,
MIIM_BITMAP, MIIM_STATE, MIIM_STRING, SW_MINIMIZE, TPM_LEFTALIGN, WM_COMMAND,
WM_DESTROY,
MIIM_BITMAP, MIIM_STATE, MIIM_STRING, SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE, TPM_LEFTALIGN,
WM_COMMAND, WM_DESTROY,
},
},
};
@ -1099,6 +1099,12 @@ unsafe extern "system" fn menu_subclass_proc(
PredfinedMenuItemType::Minimize => {
ShowWindow(hwnd, SW_MINIMIZE);
}
PredfinedMenuItemType::Maximize => {
ShowWindow(hwnd, SW_MAXIMIZE);
}
PredfinedMenuItemType::Hide => {
ShowWindow(hwnd, SW_HIDE);
}
PredfinedMenuItemType::CloseWindow => {
DestroyWindow(hwnd);
}

View file

@ -27,73 +27,134 @@ unsafe impl MenuItemExt for PredefinedMenuItem {
}
impl PredefinedMenuItem {
/// Separator menu item
pub fn separator() -> PredefinedMenuItem {
PredefinedMenuItem::new::<&str>(PredfinedMenuItemType::Separator, None)
}
/// Copy menu item
pub fn copy(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Copy, text)
}
/// Cut menu item
pub fn cut(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Cut, text)
}
/// Paste menu item
pub fn paste(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Paste, text)
}
/// SelectAll menu item
pub fn select_all(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::SelectAll, text)
}
/// Undo menu item
///
/// ## Platform-specific:
///
/// - **Windows / Linux:** Unsupported.
pub fn undo(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Undo, text)
}
/// Redo menu item
///
/// ## Platform-specific:
///
/// - **Windows / Linux:** Unsupported.
pub fn redo(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Redo, text)
}
/// Minimize window menu item
///
/// ## Platform-specific:
///
/// - **Linux:** Unsupported.
pub fn minimize(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Minimize, text)
}
/// Maximize window menu item
///
/// ## Platform-specific:
///
/// - **Linux:** Unsupported.
pub fn maximize(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Maximize, text)
}
/// Fullscreen menu item
///
/// ## Platform-specific:
///
/// - **Windows / Linux:** Unsupported.
pub fn fullscreen(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Fullscreen, text)
}
/// Hide window menu item
///
/// ## Platform-specific:
///
/// - **Linux:** Unsupported.
pub fn hide(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Hide, text)
}
/// Hide other windows menu item
///
/// ## Platform-specific:
///
/// - **Linux:** Unsupported.
pub fn hide_others(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::HideOthers, text)
}
/// Show all app windows menu item
///
/// ## Platform-specific:
///
/// - **Windows / Linux:** Unsupported.
pub fn show_all(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::ShowAll, text)
}
/// Close window menu item
///
/// ## Platform-specific:
///
/// - **Linux:** Unsupported.
pub fn close_window(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::CloseWindow, text)
}
/// Quit app menu item
///
/// ## Platform-specific:
///
/// - **Linux:** Unsupported.
pub fn quit(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Quit, text)
}
/// About app menu item
pub fn about(text: Option<&str>, metadata: Option<AboutMetadata>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::About(metadata), text)
}
/// Services menu item
///
/// ## Platform-specific:
///
/// - **Windows / Linux:** Unsupported.
pub fn services(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Services, text)
}
fn new<S: AsRef<str>>(item: PredfinedMenuItemType, text: Option<S>) -> Self {
Self(crate::platform_impl::PredefinedMenuItem::new(
item,
@ -184,9 +245,9 @@ impl PredfinedMenuItemType {
#[cfg(target_os = "macos")]
PredfinedMenuItemType::Maximize => "Zoom",
#[cfg(not(target_os = "macos"))]
PredfinedMenuItemType::Maximize => "Maximize",
PredfinedMenuItemType::Maximize => "Ma&ximize",
PredfinedMenuItemType::Fullscreen => "Toggle Full Screen",
PredfinedMenuItemType::Hide => "Hide",
PredfinedMenuItemType::Hide => "&Hide",
PredfinedMenuItemType::HideOthers => "Hide Others",
PredfinedMenuItemType::ShowAll => "Show All",
#[cfg(windows)]