diff --git a/examples/open_window.rs b/examples/open_window.rs index ed3d0fc..b248b55 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -14,7 +14,7 @@ struct OpenWindowExample { } impl WindowHandler for OpenWindowExample { - fn on_frame(&mut self) { + fn on_frame(&mut self, _window: &mut Window) { while let Ok(message) = self.rx.pop() { println!("Message: {:?}", message); } diff --git a/src/macos/window.rs b/src/macos/window.rs index 3ff19bb..8841e8e 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -217,15 +217,14 @@ impl WindowState { &mut *(state_ptr as *mut Self) } - pub(super) fn trigger_event(&mut self, event: Event){ - self.window_handler.on_event( - &mut crate::Window::new(&mut self.window), - event - ); + pub(super) fn trigger_event(&mut self, event: Event) { + self.window_handler + .on_event(&mut crate::Window::new(&mut self.window), event); } - pub(super) fn trigger_frame(&mut self){ - self.window_handler.on_frame() + pub(super) fn trigger_frame(&mut self) { + self.window_handler + .on_frame(&mut crate::Window::new(&mut self.window)); } pub(super) fn process_native_key_event( @@ -236,11 +235,11 @@ impl WindowState { } /// Don't call until WindowState pointer is stored in view - unsafe fn setup_timer(window_state_ptr: *mut WindowState){ + unsafe fn setup_timer(window_state_ptr: *mut WindowState) { extern "C" fn timer_callback( _: *mut __CFRunLoopTimer, window_state_ptr: *mut c_void, - ){ + ) { unsafe { let window_state = &mut *( window_state_ptr as *mut WindowState @@ -276,8 +275,8 @@ impl WindowState { } /// Call when freeing view - pub(super) unsafe fn remove_timer(&mut self){ - if let Some(frame_timer) = self.frame_timer.take(){ + pub(super) unsafe fn remove_timer(&mut self) { + if let Some(frame_timer) = self.frame_timer.take() { CFRunLoop::get_current() .remove_timer(&frame_timer, kCFRunLoopDefaultMode); } diff --git a/src/win/window.rs b/src/win/window.rs index 57c762f..6d4de61 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -137,7 +137,7 @@ unsafe extern "system" fn wnd_proc( WM_TIMER => { match wparam { WIN_FRAME_TIMER => { - (&*window_state_ptr).borrow_mut().handler.on_frame(); + (&*window_state_ptr).borrow_mut().handler.on_frame(&mut window); } _ => (), } diff --git a/src/window.rs b/src/window.rs index 480f2ce..88f5340 100644 --- a/src/window.rs +++ b/src/window.rs @@ -13,7 +13,7 @@ use crate::win as platform; use crate::x11 as platform; pub trait WindowHandler { - fn on_frame(&mut self); + fn on_frame(&mut self, window: &mut Window); fn on_event(&mut self, window: &mut Window, event: Event); } diff --git a/src/x11/window.rs b/src/x11/window.rs index 0cfe30ec..f0e7f0a 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -273,7 +273,7 @@ impl Window { while self.event_loop_running { let now = Instant::now(); let until_next_frame = if now > next_frame { - handler.on_frame(); + handler.on_frame(&mut crate::Window::new(self)); next_frame = Instant::now() + self.frame_interval; self.frame_interval