1
0
Fork 0

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).
This commit is contained in:
William Light 2020-09-11 16:49:55 +02:00
parent b650bf772f
commit 072918cb3f
3 changed files with 7 additions and 7 deletions

View file

@ -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) {}
}

View file

@ -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);
}

View file

@ -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::<xcb::MotionNotifyEvent>(&event) };