1
1
use heat_wgpu:: app:: App ;
2
- use winit:: { event_loop:: EventLoop , window:: WindowBuilder , event:: { Event , WindowEvent } , keyboard:: { KeyCode , PhysicalKey :: Code } } ;
3
-
4
-
2
+ use winit:: {
3
+ event:: { Event , WindowEvent } ,
4
+ event_loop:: EventLoop ,
5
+ keyboard:: { KeyCode , PhysicalKey :: Code } ,
6
+ window:: WindowBuilder ,
7
+ } ;
5
8
6
9
fn main ( ) {
7
10
env_logger:: init ( ) ;
@@ -11,45 +14,47 @@ fn main() {
11
14
. expect ( "Window builder creation failed" ) ;
12
15
let mut app = pollster:: block_on ( App :: new ( & window) ) ;
13
16
14
- event_loop. run ( move |event, event_loop_window_target| {
15
- match event {
16
- Event :: WindowEvent {
17
- ref event,
18
- window_id,
19
- } if window_id == window. id ( ) => {
20
- match & event {
21
- WindowEvent :: Resized ( physical_size) => app. resize ( * physical_size) ,
22
- WindowEvent :: ScaleFactorChanged { .. } => {
23
- app. resize ( window. inner_size ( ) ) ;
24
- }
25
- WindowEvent :: CloseRequested => event_loop_window_target. exit ( ) ,
26
- WindowEvent :: KeyboardInput { event, .. } => {
27
- if event. state . is_pressed ( )
28
- && matches ! ( event. physical_key, Code ( KeyCode :: Escape ) )
29
- {
30
- event_loop_window_target. exit ( ) ;
17
+ event_loop
18
+ . run ( move |event, event_loop_window_target| {
19
+ match event {
20
+ Event :: WindowEvent {
21
+ ref event,
22
+ window_id,
23
+ } if window_id == window. id ( ) => {
24
+ match & event {
25
+ WindowEvent :: Resized ( physical_size) => app. resize ( * physical_size) ,
26
+ WindowEvent :: ScaleFactorChanged { .. } => {
27
+ app. resize ( window. inner_size ( ) ) ;
31
28
}
32
- }
33
- WindowEvent :: RedrawRequested => {
34
- app. update ( ) ;
29
+ WindowEvent :: CloseRequested => event_loop_window_target. exit ( ) ,
30
+ WindowEvent :: KeyboardInput { event, .. } => {
31
+ if event. state . is_pressed ( )
32
+ && matches ! ( event. physical_key, Code ( KeyCode :: Escape ) )
33
+ {
34
+ event_loop_window_target. exit ( ) ;
35
+ }
36
+ }
37
+ WindowEvent :: RedrawRequested => {
38
+ app. update ( ) ;
35
39
36
- match app. render ( & window) {
37
- Ok ( _) => { }
38
- // Recreate the swap_chain if lost
39
- Err ( wgpu:: SurfaceError :: Lost ) => app. reacquire_size ( ) ,
40
- // The system is out of memory, we should probably quit
41
- Err ( wgpu:: SurfaceError :: OutOfMemory ) => event_loop_window_target. exit ( ) ,
42
- // All other errors (Outdated, Timeout) should be resolved by the next frame
43
- Err ( e) => eprintln ! ( "Unhandled error: {:?}" , e) ,
40
+ match app. render ( & window) {
41
+ Ok ( _) => { }
42
+ // Recreate the swap_chain if lost
43
+ Err ( wgpu:: SurfaceError :: Lost ) => app. reacquire_size ( ) ,
44
+ // The system is out of memory, we should probably quit
45
+ Err ( wgpu:: SurfaceError :: OutOfMemory ) => {
46
+ event_loop_window_target. exit ( )
47
+ }
48
+ // All other errors (Outdated, Timeout) should be resolved by the next frame
49
+ Err ( e) => eprintln ! ( "Unhandled error: {:?}" , e) ,
50
+ }
44
51
}
52
+ _ => { }
45
53
}
46
- _ => { }
47
54
}
55
+ Event :: AboutToWait => window. request_redraw ( ) ,
56
+ _ => { }
48
57
}
49
- Event :: AboutToWait => {
50
- window. request_redraw ( )
51
- }
52
- _ => { }
53
- }
54
- } ) . unwrap ( ) ;
58
+ } )
59
+ . unwrap ( ) ;
55
60
}
0 commit comments