Take a reference to a window in GraphicsContext::new, like glutin and wgpu

This commit is contained in:
Jeremy Soller 2022-12-20 08:43:26 -07:00
parent 85b4f189bd
commit 99d63063b6
13 changed files with 40 additions and 78 deletions

View file

@ -63,15 +63,15 @@ use winit::window::WindowBuilder;
fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
let mut graphics_context = unsafe { GraphicsContext::new(&window) }.unwrap();
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::RedrawRequested(window_id) if window_id == graphics_context.window().id() => {
Event::RedrawRequested(window_id) if window_id == window.id() => {
let (width, height) = {
let size = graphics_context.window().inner_size();
let size = window.inner_size();
(size.width, size.height)
};
let buffer = (0..((width * height) as usize))
@ -93,7 +93,7 @@ fn main() {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == graphics_context.window().id() => {
} if window_id == window.id() => {
*control_flow = ControlFlow::Exit;
}
_ => {}