docs: update docs

This commit is contained in:
amrbashir 2023-02-08 21:00:29 +02:00
parent d7905d5f22
commit 4b2ebc247c
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33
5 changed files with 67 additions and 32 deletions

5
.changes/docs.md Normal file
View file

@ -0,0 +1,5 @@
---
"muda": "patch"
---
Update docs

View file

@ -1,5 +1,33 @@
muda is a Menu Utilities library for Desktop Applications.
## Platforms supported:
- Windows
- macOS
- Linux (gtk Only)
## Platform-specific notes:
- On Windows, accelerators don't work unless the win32 message loop calls
[`TranslateAcceleratorW`](https://docs.rs/windows-sys/latest/windows_sys/Win32/UI/WindowsAndMessaging/fn.TranslateAcceleratorW.html).
See [`Menu::init_for_hwnd`](https://docs.rs/muda/latest/muda/struct.Menu.html#method.init_for_hwnd) for more details
## Dependencies (Linux Only)
`gtk` is used for menus and `libxdo` is used to make the predfined `Copy`, `Cut`, `Paste` and `SelectAll` menu items work. Be sure to install following packages before building:
#### Arch Linux / Manjaro:
```sh
pacman -S gtk3 xdotool
```
#### Debian / Ubuntu:
```sh
sudo apt install libgtk-3-dev libxdo-dev
```
## Example
Create the menu and add your items
@ -50,10 +78,12 @@ menu.show_context_menu_for_gtk_window(&gtk_window, x, y);
#[cfg(target_os = "macos")]
menu.show_context_menu_for_nsview(nsview, x, y);
```
## Processing menu events
You can use `MenuEvent::receiver` to get a reference to the `MenuEventReceiver`
which you can use to listen to events when a menu item is activated
```rs
if let Ok(event) = MenuEvent::receiver().try_recv() {
match event.id {
@ -65,29 +95,6 @@ if let Ok(event) = MenuEvent::receiver().try_recv() {
}
```
## Platform-specific notes:
### Accelerators on Windows
Accelerators don't work unless the win32 message loop calls
[`TranslateAcceleratorW`](https://docs.rs/windows-sys/latest/windows_sys/Win32/UI/WindowsAndMessaging/fn.TranslateAcceleratorW.html)
See [`Menu::init_for_hwnd`](https://docs.rs/muda/latest/muda/struct.Menu.html#method.init_for_hwnd) for more details
### Linux
`libxdo` is used to make the predfined `Copy`, `Cut`, `Paste` and `SelectAll` menu items work. Be sure to install following packages before building:
Arch Linux / Manjaro:
```sh
pacman -S xdotool
```
Debian / Ubuntu:
```sh
sudo apt install libxdo-dev
```
## License
Apache-2.0/MIT

View file

@ -190,7 +190,7 @@ fn main() {
if event.id == custom_i_1.id() {
file_m.insert(&MenuItem::new("New Menu Item", true, None), 2);
}
println!("{:?}", event);
println!("{event:?}");
}
})
}

View file

@ -180,7 +180,7 @@ fn main() {
if event.id == custom_i_1.id() {
file_m.insert(&MenuItem::new("New Menu Item", true, None), 2);
}
println!("{:?}", event);
println!("{event:?}");
}
})
}

View file

@ -2,8 +2,38 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![allow(clippy::uninlined_format_args)]
//! muda is a Menu Utilities library for Desktop Applications.
//!
//! # Platforms supported:
//!
//! - Windows
//! - macOS
//! - Linux (gtk Only)
//!
//! # Platform-specific notes:
//!
//! - On Windows, accelerators don't work unless the win32 message loop calls
//! [`TranslateAcceleratorW`](https://docs.rs/windows-sys/latest/windows_sys/Win32/UI/WindowsAndMessaging/fn.TranslateAcceleratorW.html).
//! See [`Menu::init_for_hwnd`](https://docs.rs/muda/latest/muda/struct.Menu.html#method.init_for_hwnd) for more details
//!
//! # Dependencies (Linux Only)
//!
//! `gtk` is used for menus and `libxdo` is used to make the predfined `Copy`, `Cut`, `Paste` and `SelectAll` menu items work. Be sure to install following packages before building:
//!
//! #### Arch Linux / Manjaro:
//!
//! ```sh
//! pacman -S gtk3 xdotool
//! ```
//!
//! #### Debian / Ubuntu:
//!
//! ```sh
//! sudo apt install libgtk-3-dev libxdo-dev
//! ```
//!
//! # Example
//!
//! Create the menu and add your items
@ -94,13 +124,6 @@
//! }
//! }
//! ```
//!
//! # Accelerators on Windows
//!
//! Accelerators don't work unless the win32 message loop calls
//! [`TranslateAcceleratorW`](windows_sys::Win32::UI::WindowsAndMessaging::TranslateAcceleratorW)
//!
//! See [`Menu::init_for_hwnd`] for more details
use crossbeam_channel::{unbounded, Receiver, Sender};
use once_cell::sync::{Lazy, OnceCell};