Skip to content

Commit 663f9d5

Browse files
authored
Merge pull request #88 from glowcoil/on_frame_window
add window argument to WindowHandler::on_frame()
2 parents 36e4474 + ef27ade commit 663f9d5

5 files changed

Lines changed: 14 additions & 15 deletions

File tree

examples/open_window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct OpenWindowExample {
1414
}
1515

1616
impl WindowHandler for OpenWindowExample {
17-
fn on_frame(&mut self) {
17+
fn on_frame(&mut self, _window: &mut Window) {
1818
while let Ok(message) = self.rx.pop() {
1919
println!("Message: {:?}", message);
2020
}

src/macos/window.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,14 @@ impl WindowState {
217217
&mut *(state_ptr as *mut Self)
218218
}
219219

220-
pub(super) fn trigger_event(&mut self, event: Event){
221-
self.window_handler.on_event(
222-
&mut crate::Window::new(&mut self.window),
223-
event
224-
);
220+
pub(super) fn trigger_event(&mut self, event: Event) {
221+
self.window_handler
222+
.on_event(&mut crate::Window::new(&mut self.window), event);
225223
}
226224

227-
pub(super) fn trigger_frame(&mut self){
228-
self.window_handler.on_frame()
225+
pub(super) fn trigger_frame(&mut self) {
226+
self.window_handler
227+
.on_frame(&mut crate::Window::new(&mut self.window));
229228
}
230229

231230
pub(super) fn process_native_key_event(
@@ -236,11 +235,11 @@ impl WindowState {
236235
}
237236

238237
/// Don't call until WindowState pointer is stored in view
239-
unsafe fn setup_timer(window_state_ptr: *mut WindowState){
238+
unsafe fn setup_timer(window_state_ptr: *mut WindowState) {
240239
extern "C" fn timer_callback(
241240
_: *mut __CFRunLoopTimer,
242241
window_state_ptr: *mut c_void,
243-
){
242+
) {
244243
unsafe {
245244
let window_state = &mut *(
246245
window_state_ptr as *mut WindowState
@@ -276,8 +275,8 @@ impl WindowState {
276275
}
277276

278277
/// Call when freeing view
279-
pub(super) unsafe fn remove_timer(&mut self){
280-
if let Some(frame_timer) = self.frame_timer.take(){
278+
pub(super) unsafe fn remove_timer(&mut self) {
279+
if let Some(frame_timer) = self.frame_timer.take() {
281280
CFRunLoop::get_current()
282281
.remove_timer(&frame_timer, kCFRunLoopDefaultMode);
283282
}

src/win/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ unsafe extern "system" fn wnd_proc(
137137
WM_TIMER => {
138138
match wparam {
139139
WIN_FRAME_TIMER => {
140-
(&*window_state_ptr).borrow_mut().handler.on_frame();
140+
(&*window_state_ptr).borrow_mut().handler.on_frame(&mut window);
141141
}
142142
_ => (),
143143
}

src/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::win as platform;
1313
use crate::x11 as platform;
1414

1515
pub trait WindowHandler {
16-
fn on_frame(&mut self);
16+
fn on_frame(&mut self, window: &mut Window);
1717
fn on_event(&mut self, window: &mut Window, event: Event);
1818
}
1919

src/x11/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl Window {
273273
while self.event_loop_running {
274274
let now = Instant::now();
275275
let until_next_frame = if now > next_frame {
276-
handler.on_frame();
276+
handler.on_frame(&mut crate::Window::new(self));
277277

278278
next_frame = Instant::now() + self.frame_interval;
279279
self.frame_interval

0 commit comments

Comments
 (0)