44use log:: debug;
55use pixels:: { Error , Pixels , SurfaceTexture } ;
66use winit:: dpi:: { LogicalPosition , LogicalSize , PhysicalSize } ;
7- use winit:: event:: { Event , VirtualKeyCode , WindowEvent } ;
7+ use winit:: event:: { Event , VirtualKeyCode } ;
88use winit:: event_loop:: { ControlFlow , EventLoop } ;
99use winit_input_helper:: WinitInputHelper ;
1010
@@ -15,7 +15,7 @@ fn main() -> Result<(), Error> {
1515 env_logger:: init ( ) ;
1616 let event_loop = EventLoop :: new ( ) ;
1717 let mut input = WinitInputHelper :: new ( ) ;
18- let ( window, surface, mut p_width, mut p_height, mut hidpi_factor) =
18+ let ( window, surface, p_width, p_height, mut hidpi_factor) =
1919 create_window ( "Conway's Game of Life" , & event_loop) ;
2020
2121 let surface_texture = SurfaceTexture :: new ( p_width, p_height, surface) ;
@@ -28,13 +28,9 @@ fn main() -> Result<(), Error> {
2828
2929 event_loop. run ( move |event, _, control_flow| {
3030 // The one and only event that winit_input_helper doesn't have for us...
31- if let Event :: WindowEvent {
32- event : WindowEvent :: RedrawRequested ,
33- ..
34- } = event
35- {
31+ if let Event :: RedrawRequested ( _) = event {
3632 life. draw ( pixels. get_frame ( ) ) ;
37- pixels. render ( ) ;
33+ pixels. render ( ) . unwrap ( ) ;
3834 }
3935
4036 // For everything else, for let winit_input_helper collect events to build its state.
@@ -100,15 +96,12 @@ fn main() -> Result<(), Error> {
10096 }
10197 }
10298 // Adjust high DPI factor
103- if let Some ( factor) = input. hidpi_changed ( ) {
99+ if let Some ( factor) = input. scale_factor_changed ( ) {
104100 hidpi_factor = factor;
105101 }
106102 // Resize the window
107103 if let Some ( size) = input. window_resized ( ) {
108- let size = size. to_physical ( hidpi_factor) ;
109- p_width = size. width . round ( ) as u32 ;
110- p_height = size. height . round ( ) as u32 ;
111- pixels. resize ( p_width, p_height) ;
104+ pixels. resize ( size. width , size. height ) ;
112105 }
113106 if !paused || input. key_pressed ( VirtualKeyCode :: Space ) {
114107 life. update ( ) ;
@@ -138,19 +131,23 @@ fn create_window(
138131 . with_title ( title)
139132 . build ( & event_loop)
140133 . unwrap ( ) ;
141- let hidpi_factor = window. hidpi_factor ( ) ;
134+ let hidpi_factor = window. scale_factor ( ) ;
142135
143136 // Get dimensions
144137 let width = SCREEN_WIDTH as f64 ;
145138 let height = SCREEN_HEIGHT as f64 ;
146139 let ( monitor_width, monitor_height) = {
147140 let size = window. current_monitor ( ) . size ( ) ;
148- ( size. width / hidpi_factor, size. height / hidpi_factor)
141+ (
142+ size. width as f64 / hidpi_factor,
143+ size. height as f64 / hidpi_factor,
144+ )
149145 } ;
150146 let scale = ( monitor_height / height * 2.0 / 3.0 ) . round ( ) ;
151147
152148 // Resize, center, and display the window
153- let min_size = PhysicalSize :: new ( width, height) . to_logical ( hidpi_factor) ;
149+ let min_size: winit:: dpi:: LogicalSize < f64 > =
150+ PhysicalSize :: new ( width, height) . to_logical ( hidpi_factor) ;
154151 let default_size = LogicalSize :: new ( width * scale, height * scale) ;
155152 let center = LogicalPosition :: new (
156153 ( monitor_width - width * scale) / 2.0 ,
@@ -162,7 +159,7 @@ fn create_window(
162159 window. set_visible ( true ) ;
163160
164161 let surface = pixels:: wgpu:: Surface :: create ( & window) ;
165- let size = default_size. to_physical ( hidpi_factor) ;
162+ let size = default_size. to_physical :: < f64 > ( hidpi_factor) ;
166163
167164 (
168165 window,
@@ -302,14 +299,14 @@ impl ConwayGrid {
302299 } else {
303300 ( y - 1 , y + 1 )
304301 } ;
305- ( self . cells [ xm1 + ym1 * self . width ] . alive as usize
302+ self . cells [ xm1 + ym1 * self . width ] . alive as usize
306303 + self . cells [ x + ym1 * self . width ] . alive as usize
307304 + self . cells [ xp1 + ym1 * self . width ] . alive as usize
308305 + self . cells [ xm1 + y * self . width ] . alive as usize
309306 + self . cells [ xp1 + y * self . width ] . alive as usize
310307 + self . cells [ xm1 + yp1 * self . width ] . alive as usize
311308 + self . cells [ x + yp1 * self . width ] . alive as usize
312- + self . cells [ xp1 + yp1 * self . width ] . alive as usize )
309+ + self . cells [ xp1 + yp1 * self . width ] . alive as usize
313310 }
314311
315312 fn update ( & mut self ) {
0 commit comments