mirror of
https://github.com/italicsjenga/muda.git
synced 2024-12-23 20:11:29 +11:00
Add init_for_nsapp
This commit is contained in:
parent
b5886fe6b1
commit
413358ed85
|
@ -20,6 +20,8 @@ let cut_item = file_menu.add_text_item("Cut", true);
|
|||
menu.init_for_hwnd(window.hwnd() as isize);
|
||||
#[cfg(target_os = "linux")]
|
||||
menu.init_for_gtk_window(>k_window);
|
||||
#[cfg(target_os = "macos")]
|
||||
menu.init_for_nsapp();
|
||||
```
|
||||
Then listen for the events
|
||||
```rs
|
||||
|
|
|
@ -38,6 +38,11 @@ fn main() {
|
|||
menu_bar.init_for_gtk_window(window2.gtk_window());
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
menu_bar.init_for_nsapp();
|
||||
}
|
||||
|
||||
let menu_channel = menu_event_receiver();
|
||||
let mut open_item_disabled = false;
|
||||
let mut counter = 0;
|
||||
|
|
|
@ -31,6 +31,11 @@ fn main() {
|
|||
menu_bar.init_for_hwnd(_window2.hwnd() as _);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
menu_bar.init_for_nsapp();
|
||||
}
|
||||
|
||||
let menu_channel = menu_event_receiver();
|
||||
let mut open_item_disabled = false;
|
||||
let mut counter = 0;
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
//! menu.init_for_hwnd(window.hwnd() as isize);
|
||||
//! #[cfg(target_os = "linux")]
|
||||
//! menu.init_for_gtk_window(>k_window);
|
||||
//! #[cfg(target_os = "macos")]
|
||||
//! menu.init_for_nsapp();
|
||||
//! ```
|
||||
//!
|
||||
//! # Processing menu events
|
||||
|
@ -118,6 +120,12 @@ impl Menu {
|
|||
pub fn init_for_hwnd(&self, hwnd: isize) {
|
||||
self.0.init_for_hwnd(hwnd)
|
||||
}
|
||||
|
||||
/// Adds this menu to NSApp.
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn init_for_nsapp(&self) {
|
||||
self.0.init_for_nsapp()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -23,10 +23,23 @@ impl Menu {
|
|||
|
||||
pub fn add_submenu(&mut self, label: impl AsRef<str>, enabled: bool) -> Submenu {
|
||||
let mut sub_menu = Submenu(Menu::new());
|
||||
sub_menu.set_label(label);
|
||||
sub_menu.set_label(label.as_ref());
|
||||
sub_menu.set_enabled(enabled);
|
||||
let item = TextMenuItem::new(label, enabled, sel!(fireMenubarAction:));
|
||||
|
||||
unsafe {
|
||||
item.ns_menu_item.setSubmenu_(sub_menu.0 .0);
|
||||
self.0.addItem_(item.ns_menu_item);
|
||||
}
|
||||
|
||||
sub_menu
|
||||
}
|
||||
|
||||
pub fn init_for_nsapp(&self) {
|
||||
unsafe {
|
||||
NSApp().setMainMenu_(self.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
Loading…
Reference in a new issue