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
46
47
use App;
use glium::{self, glutin};
pub use glium::glutin::WindowId as Id;
pub struct Builder<'a, 'b> {
app: &'a App,
window: glutin::WindowBuilder,
context: glutin::ContextBuilder<'b>,
}
impl<'a, 'b> Builder<'a, 'b> {
pub fn new(app: &'a App) -> Self {
Builder {
app,
window: glutin::WindowBuilder::new(),
context: glutin::ContextBuilder::new(),
}
}
pub fn window(mut self, window: glutin::WindowBuilder) -> Self {
self.window = window;
self
}
pub fn context<'c>(self, context: glutin::ContextBuilder<'c>) -> Builder<'a, 'c> {
let Builder { app, window, .. } = self;
Builder { app, window, context }
}
pub fn build(self) -> Result<Id, glium::backend::glutin::DisplayCreationError> {
let Builder { app, window, context } = self;
let display = glium::Display::new(window, context, &app.events_loop)?;
let window_id = display.gl_window().id();
app.displays.borrow_mut().insert(window_id, display);
Ok(window_id)
}
}