api unification: make cross-platform Window hold a reference
This commit is contained in:
parent
f9226c366e
commit
185bd62447
|
@ -63,7 +63,7 @@ impl Window {
|
|||
{
|
||||
let _pool = unsafe { NSAutoreleasePool::new(nil) };
|
||||
|
||||
let window = match options.parent {
|
||||
let mut window = match options.parent {
|
||||
Parent::WithParent(parent) => {
|
||||
if let RawWindowHandle::MacOS(handle) = parent {
|
||||
let ns_view = handle.ns_view as *mut objc::runtime::Object;
|
||||
|
@ -155,12 +155,10 @@ impl Window {
|
|||
},
|
||||
};
|
||||
|
||||
let mut window = crate::window::Window(window);
|
||||
|
||||
let window_handler = build(&mut window);
|
||||
let window_handler = build(&mut crate::window::Window(&mut window));
|
||||
|
||||
let window_state_arc = Arc::new(WindowState {
|
||||
window: window,
|
||||
window,
|
||||
window_handler,
|
||||
keyboard_state: KeyboardState::new(),
|
||||
});
|
||||
|
@ -170,7 +168,7 @@ impl Window {
|
|||
) as *mut c_void;
|
||||
|
||||
unsafe {
|
||||
(*window_state_arc.window.0.ns_view).set_ivar(
|
||||
(*window_state_arc.window.ns_view).set_ivar(
|
||||
WINDOW_STATE_IVAR_NAME,
|
||||
window_state_pointer
|
||||
);
|
||||
|
@ -185,13 +183,13 @@ impl Window {
|
|||
let timer: id = msg_send![
|
||||
::objc::class!(NSTimer),
|
||||
scheduledTimerWithTimeInterval:timer_interval
|
||||
target:window_state_arc.window.0.ns_view
|
||||
target:window_state_arc.window.ns_view
|
||||
selector:selector
|
||||
userInfo:nil
|
||||
repeats:YES
|
||||
];
|
||||
|
||||
(*window_state_arc.window.0.ns_view).set_ivar(
|
||||
(*window_state_arc.window.ns_view).set_ivar(
|
||||
FRAME_TIMER_IVAR_NAME,
|
||||
timer as *mut c_void,
|
||||
)
|
||||
|
@ -203,7 +201,7 @@ impl Window {
|
|||
|
||||
|
||||
pub(super) struct WindowState<H: WindowHandler> {
|
||||
window: crate::window::Window,
|
||||
window: Window,
|
||||
window_handler: H,
|
||||
keyboard_state: KeyboardState,
|
||||
}
|
||||
|
@ -222,7 +220,10 @@ impl <H: WindowHandler>WindowState<H> {
|
|||
}
|
||||
|
||||
pub(super) fn trigger_event(&mut self, event: Event){
|
||||
self.window_handler.on_event(&mut self.window, event);
|
||||
self.window_handler.on_event(
|
||||
&mut crate::window::Window(&mut self.window),
|
||||
event
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn trigger_frame(&mut self){
|
||||
|
|
|
@ -72,7 +72,8 @@ unsafe extern "system" fn wnd_proc<H: WindowHandler>(
|
|||
let win_ptr = GetWindowLongPtrA(hwnd, GWLP_USERDATA) as *const c_void;
|
||||
if !win_ptr.is_null() {
|
||||
let window_state = &*(win_ptr as *const RefCell<WindowState<H>>);
|
||||
let mut window = crate::window::Window(Window { hwnd });
|
||||
let mut window = Window { hwnd };
|
||||
let mut window = crate::window::Window(&mut window);
|
||||
|
||||
match msg {
|
||||
WM_MOUSEMOVE => {
|
||||
|
@ -240,9 +241,7 @@ impl Window {
|
|||
);
|
||||
// todo: manage error ^
|
||||
|
||||
let mut window = crate::window::Window(Window { hwnd });
|
||||
|
||||
let handler = build(&mut window);
|
||||
let handler = build(&mut crate::window::Window(&mut Window { hwnd }));
|
||||
|
||||
let window_state = Box::new(RefCell::new(WindowState {
|
||||
window_class,
|
||||
|
|
|
@ -19,10 +19,10 @@ impl WindowHandle {
|
|||
}
|
||||
|
||||
|
||||
pub struct Window(pub(crate) platform::Window);
|
||||
pub struct Window<'a>(pub(crate) &'a mut platform::Window);
|
||||
|
||||
|
||||
impl Window {
|
||||
impl <'a>Window<'a> {
|
||||
pub fn open<H, B>(
|
||||
options: WindowOpenOptions,
|
||||
build: B
|
||||
|
|
Loading…
Reference in a new issue