feat: expose macOS NSMenu

This commit is contained in:
amrbashir 2022-11-24 18:07:11 +02:00
parent 812ff0d37a
commit 37153b826f
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33
4 changed files with 30 additions and 0 deletions

View file

@ -209,6 +209,9 @@ pub trait ContextMenu {
/// (the click which triggered the menu to be shown).
#[cfg(target_os = "macos")]
fn show_context_menu_for_nsview(&self, view: cocoa::base::id, x: f64, y: f64);
#[cfg(target_os = "macos")]
fn ns_menu(&self) -> *mut std::ffi::c_void;
}
/// Describes a menu event emitted when a menu item is activated

View file

@ -46,6 +46,11 @@ impl ContextMenu for Menu {
fn show_context_menu_for_nsview(&self, view: cocoa::base::id, x: f64, y: f64) {
self.0.show_context_menu_for_nsview(view, x, y)
}
#[cfg(target_os = "macos")]
fn ns_menu(&self) -> *mut std::ffi::c_void {
self.0.ns_menu()
}
}
impl Menu {

View file

@ -242,6 +242,10 @@ impl Menu {
msg_send![self.ns_menu, popUpMenuPositioningItem: nil atLocation: location inView: view]
}
}
pub fn ns_menu(&self) -> *mut std::ffi::c_void {
self.ns_menu as _
}
}
#[derive(Clone)]
@ -446,6 +450,19 @@ impl Submenu {
unsafe { msg_send![NSApp(), setHelpMenu: ns_menus[0]] }
}
}
pub fn ns_menu(&self) -> *mut std::ffi::c_void {
*self
.0
.borrow()
.ns_menus
.values()
.collect::<Vec<_>>()
.get(0)
.unwrap()
.get(0)
.unwrap() as _
}
}
#[derive(Clone, Debug)]

View file

@ -54,6 +54,11 @@ impl ContextMenu for Submenu {
fn show_context_menu_for_nsview(&self, view: cocoa::base::id, x: f64, y: f64) {
self.0.show_context_menu_for_nsview(view, x, y)
}
#[cfg(target_os = "macos")]
fn ns_menu(&self) -> *mut std::ffi::c_void {
self.0.ns_menu()
}
}
impl Submenu {