@@ -6,7 +6,6 @@ mod winit_app;
66
77#[ cfg( not( target_family = "wasm" ) ) ]
88pub mod ex {
9- use std:: num:: NonZeroU32 ;
109 use std:: sync:: { mpsc, Arc , Mutex } ;
1110 use winit:: event:: { KeyEvent , WindowEvent } ;
1211 use winit:: event_loop:: { ControlFlow , EventLoop , OwnedDisplayHandle } ;
@@ -31,29 +30,24 @@ pub mod ex {
3130
3231 // Perform the rendering.
3332 let mut surface = surface. lock ( ) . unwrap ( ) ;
34- if let ( Some ( width) , Some ( height) ) = {
35- let size = window. inner_size ( ) ;
36- println ! ( "got size: {size:?}" ) ;
37- ( NonZeroU32 :: new ( size. width ) , NonZeroU32 :: new ( size. height ) )
38- } {
39- println ! ( "resizing..." ) ;
40- surface. resize ( width, height) . unwrap ( ) ;
41-
42- let mut buffer = surface. buffer_mut ( ) . unwrap ( ) ;
43- for y in 0 ..buffer. height ( ) . get ( ) {
44- for x in 0 ..buffer. width ( ) . get ( ) {
45- let red = x % 255 ;
46- let green = y % 255 ;
47- let blue = ( x * y) % 255 ;
48- let index = y * buffer. width ( ) . get ( ) + x;
49- buffer[ index as usize ] = blue | ( green << 8 ) | ( red << 16 ) ;
50- }
33+ let size = window. inner_size ( ) ;
34+ println ! ( "resizing..." ) ;
35+ surface. resize ( size. width , size. height ) . unwrap ( ) ;
36+
37+ let mut buffer = surface. buffer_mut ( ) . unwrap ( ) ;
38+ for y in 0 ..buffer. height ( ) {
39+ for x in 0 ..buffer. width ( ) {
40+ let red = x % 255 ;
41+ let green = y % 255 ;
42+ let blue = ( x * y) % 255 ;
43+ let index = y * buffer. width ( ) + x;
44+ buffer[ index as usize ] = blue | ( green << 8 ) | ( red << 16 ) ;
5145 }
52-
53- println ! ( "presenting..." ) ;
54- buffer. present ( ) . unwrap ( ) ;
5546 }
5647
48+ println ! ( "presenting..." ) ;
49+ buffer. present ( ) . unwrap ( ) ;
50+
5751 // We're done, tell the main thread to keep going.
5852 done. send ( ( ) ) . ok ( ) ;
5953 }
0 commit comments