muda/README.md

37 lines
904 B
Markdown
Raw Normal View History

# muda
2022-05-07 06:57:58 +10:00
2022-05-08 21:38:30 +10:00
Menu Utilities for Desktop Applications.
2022-05-07 06:57:58 +10:00
## Example
Create the root menu and add submenus and men items.
```rs
let mut menu = Menu::new();
let file_menu = menu.add_submenu("File", true);
let open_item = file_menu.add_text_item("Open", true);
let save_item = file_menu.add_text_item("Save", true);
let edit_menu = menu.add_submenu("Edit", true);
let copy_item = file_menu.add_text_item("Copy", true);
let cut_item = file_menu.add_text_item("Cut", true);
#[cfg(target_os = "windows")]
menu.init_for_hwnd(window.hwnd() as isize);
#[cfg(target_os = "linux")]
menu.init_for_gtk_window(&gtk_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
```
Then listen for the events
```rs
if let Ok(event) = menu_event_receiver().try_recv() {
match event.id {
_ if event.id == save_item.id() => {
println!("Save menu item activated");
},
_ => {}
}
}
2022-05-07 08:52:41 +10:00
```