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>,
/// A delegate for this window.
pub delegate: Option<Box<T>>
pub delegate: Option<Box<T>>,
}
impl Default for Window {
@ -108,21 +108,21 @@ impl Window {
Window {
objc: objc,
delegate: None
delegate: None,
}
}
pub(crate) unsafe fn existing(window: *mut Object) -> Window {
Window {
objc: Id::retain(window).unwrap(),
delegate: None
delegate: None,
}
}
}
impl<T> Window<T>
where
T: WindowDelegate + 'static
T: WindowDelegate + 'static,
{
/// 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
@ -180,13 +180,13 @@ where
{
(&mut delegate).did_load(Window {
delegate: None,
objc: objc.clone()
objc: objc.clone(),
});
}
Window {
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
pub(crate) unsafe fn content_view(&self) -> id {
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)
where
F: Fn() + Send + Sync + 'static,
W: WindowDelegate + 'static
W: WindowDelegate + 'static,
{
let block = ConcreteBlock::new(move |_response: NSInteger| {
completion();
@ -529,7 +533,7 @@ impl<T> Window<T> {
/// Closes a sheet.
pub fn end_sheet<W>(&self, window: &Window<W>)
where
W: WindowDelegate + 'static
W: WindowDelegate + 'static,
{
unsafe {
let _: () = msg_send![&*self.objc, endSheet:&*window.objc];