content view pointer

This commit is contained in:
Alex Janka 2024-02-08 15:16:43 +11:00
parent fedc3cebb6
commit da22feaebb

View file

@ -50,7 +50,7 @@ pub struct Window<T = ()> {
pub objc: Id<Object, Shared>, pub objc: Id<Object, Shared>,
/// A delegate for this window. /// A delegate for this window.
pub delegate: Option<Box<T>> pub delegate: Option<Box<T>>,
} }
impl Default for Window { impl Default for Window {
@ -108,21 +108,21 @@ impl Window {
Window { Window {
objc: objc, objc: objc,
delegate: None delegate: None,
} }
} }
pub(crate) unsafe fn existing(window: *mut Object) -> Window { pub(crate) unsafe fn existing(window: *mut Object) -> Window {
Window { Window {
objc: Id::retain(window).unwrap(), objc: Id::retain(window).unwrap(),
delegate: None delegate: None,
} }
} }
} }
impl<T> Window<T> impl<T> Window<T>
where where
T: WindowDelegate + 'static T: WindowDelegate + 'static,
{ {
/// Constructs a new Window with a `config` and `delegate`. Using a `WindowDelegate` enables /// Constructs a new Window with a `config` and `delegate`. Using a `WindowDelegate` enables
/// you to respond to window lifecycle events - visibility, movement, and so on. It also /// you to respond to window lifecycle events - visibility, movement, and so on. It also
@ -180,13 +180,13 @@ where
{ {
(&mut delegate).did_load(Window { (&mut delegate).did_load(Window {
delegate: None, delegate: None,
objc: objc.clone() objc: objc.clone(),
}); });
} }
Window { Window {
objc: objc, objc: objc,
delegate: Some(delegate) delegate: Some(delegate),
} }
} }
} }
@ -338,6 +338,10 @@ impl<T> Window<T> {
} }
} }
pub unsafe fn content_view_ptr(&self) -> Option<std::ptr::NonNull<std::ffi::c_void>> {
std::ptr::NonNull::new(self.content_view() as *mut std::ffi::c_void)
}
/// Return the objc ContentView from the window /// Return the objc ContentView from the window
pub(crate) unsafe fn content_view(&self) -> id { pub(crate) unsafe fn content_view(&self) -> id {
let id: *mut Object = msg_send![&*self.objc, contentView]; let id: *mut Object = msg_send![&*self.objc, contentView];
@ -514,7 +518,7 @@ impl<T> Window<T> {
pub fn begin_sheet<F, W>(&self, window: &Window<W>, completion: F) pub fn begin_sheet<F, W>(&self, window: &Window<W>, completion: F)
where where
F: Fn() + Send + Sync + 'static, F: Fn() + Send + Sync + 'static,
W: WindowDelegate + 'static W: WindowDelegate + 'static,
{ {
let block = ConcreteBlock::new(move |_response: NSInteger| { let block = ConcreteBlock::new(move |_response: NSInteger| {
completion(); completion();
@ -529,7 +533,7 @@ impl<T> Window<T> {
/// Closes a sheet. /// Closes a sheet.
pub fn end_sheet<W>(&self, window: &Window<W>) pub fn end_sheet<W>(&self, window: &Window<W>)
where where
W: WindowDelegate + 'static W: WindowDelegate + 'static,
{ {
unsafe { unsafe {
let _: () = msg_send![&*self.objc, endSheet:&*window.objc]; let _: () = msg_send![&*self.objc, endSheet:&*window.objc];