1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use Window;
use glutin::{Event, EventsLoop, WindowEvent};
pub trait Game {
fn new(&mut Window) -> Self;
fn event(&mut self, &mut Window, Event) {}
fn draw(&mut self, &mut Window);
fn run() where Self: Sized {
let mut events = EventsLoop::new();
let mut window = Window::new(&events);
let mut game = Self::new(&mut window);
let mut running = true;
while running {
game.draw(&mut window);
window.flush();
events.poll_events(|e| {
match e {
Event::WindowEvent { event: WindowEvent::Resized(..), .. } => {
window.resize();
}
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
running = false;
}
_ => {}
}
game.event(&mut window, e);
});
}
}
}