From 072918cb3f48895413f907db7bfbc10771cbee58 Mon Sep 17 00:00:00 2001 From: William Light Date: Fri, 11 Sep 2020 16:49:55 +0200 Subject: [PATCH] rename WindowHandler.draw() to WindowHandler.on_frame() also remove the `Window` ref argument because `on_frame()` shouldn't be doing any window system ops (this is my opinion and i am happy to backpedal if it turns out to be wrong). --- examples/open_window.rs | 8 ++++---- src/lib.rs | 2 +- src/x11/window.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/open_window.rs b/examples/open_window.rs index ff64ccc..2f22de9 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -16,13 +16,13 @@ struct MyProgram {} impl WindowHandler for MyProgram { type Message = (); - fn build(window: &mut Window) -> Self { + fn build(_window: &mut Window) -> Self { Self {} } - fn draw(&mut self, _window: &mut Window) {} + fn on_frame(&mut self) {} - fn on_event(&mut self, window: &mut Window, event: Event) { + fn on_event(&mut self, _window: &mut Window, event: Event) { match event { Event::CursorMotion(x, y) => { println!("Cursor moved, x: {}, y: {}", x, y); @@ -63,5 +63,5 @@ impl WindowHandler for MyProgram { } } - fn on_message(&mut self, window: &mut Window, _message: Self::Message) {} + fn on_message(&mut self, _window: &mut Window, _message: Self::Message) {} } diff --git a/src/lib.rs b/src/lib.rs index c4ed84f..9cae115 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ pub trait WindowHandler { fn build(window: &mut Window) -> Self; - fn draw(&mut self, window: &mut Window); + fn on_frame(&mut self); fn on_event(&mut self, window: &mut Window, event: Event); fn on_message(&mut self, window: &mut Window, message: Self::Message); } diff --git a/src/x11/window.rs b/src/x11/window.rs index 807d59f..1553c34 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -135,7 +135,7 @@ impl Window { let now = Instant::now(); let until_next_frame = if now > next_frame { - handler.draw(self); + handler.on_frame(); next_frame = now + self.frame_interval; self.frame_interval @@ -188,7 +188,7 @@ impl Window { match event_type { xcb::EXPOSE => { - handler.draw(self); + handler.on_frame(); } xcb::MOTION_NOTIFY => { let event = unsafe { xcb::cast_event::(&event) };