@@ -25,67 +25,64 @@ fn main() -> Result<(), impl std::error::Error> {
25
25
event_loop. run ( move |event, _, control_flow| {
26
26
control_flow. set_wait ( ) ;
27
27
28
- match event {
29
- Event :: WindowEvent { event, .. } => {
30
- match event {
31
- WindowEvent :: CloseRequested => {
32
- // `CloseRequested` is sent when the close button on the window is pressed (or
33
- // through whatever other mechanisms the window manager provides for closing a
34
- // window). If you don't handle this event, the close button won't actually do
35
- // anything.
28
+ if let Event :: WindowEvent { event, .. } = event {
29
+ match event {
30
+ WindowEvent :: CloseRequested => {
31
+ // `CloseRequested` is sent when the close button on the window is pressed (or
32
+ // through whatever other mechanisms the window manager provides for closing a
33
+ // window). If you don't handle this event, the close button won't actually do
34
+ // anything.
36
35
37
- // A common thing to do here is prompt the user if they have unsaved work.
38
- // Creating a proper dialog box for that is far beyond the scope of this
39
- // example, so here we'll just respond to the Y and N keys.
40
- println ! ( "Are you ready to bid your window farewell? [Y/N]" ) ;
41
- close_requested = true ;
36
+ // A common thing to do here is prompt the user if they have unsaved work.
37
+ // Creating a proper dialog box for that is far beyond the scope of this
38
+ // example, so here we'll just respond to the Y and N keys.
39
+ println ! ( "Are you ready to bid your window farewell? [Y/N]" ) ;
40
+ close_requested = true ;
42
41
43
- // In applications where you can safely close the window without further
44
- // action from the user, this is generally where you'd handle cleanup before
45
- // closing the window. How to close the window is detailed in the handler for
46
- // the Y key.
47
- }
48
- WindowEvent :: KeyboardInput {
49
- event :
50
- KeyEvent {
51
- logical_key : key,
52
- state : ElementState :: Released ,
53
- ..
54
- } ,
55
- ..
56
- } => {
57
- // WARNING: Consider using `key_without_modifers()` if available on your platform.
58
- // See the `key_binding` example
59
- match key. as_ref ( ) {
60
- Key :: Character ( "y" ) => {
61
- if close_requested {
62
- // This is where you'll want to do any cleanup you need.
63
- println ! ( "Buh-bye!" ) ;
42
+ // In applications where you can safely close the window without further
43
+ // action from the user, this is generally where you'd handle cleanup before
44
+ // closing the window. How to close the window is detailed in the handler for
45
+ // the Y key.
46
+ }
47
+ WindowEvent :: KeyboardInput {
48
+ event :
49
+ KeyEvent {
50
+ logical_key : key,
51
+ state : ElementState :: Released ,
52
+ ..
53
+ } ,
54
+ ..
55
+ } => {
56
+ // WARNING: Consider using `key_without_modifers()` if available on your platform.
57
+ // See the `key_binding` example
58
+ match key. as_ref ( ) {
59
+ Key :: Character ( "y" ) => {
60
+ if close_requested {
61
+ // This is where you'll want to do any cleanup you need.
62
+ println ! ( "Buh-bye!" ) ;
64
63
65
- // For a single-window application like this, you'd normally just
66
- // break out of the event loop here. If you wanted to keep running the
67
- // event loop (i.e. if it's a multi-window application), you need to
68
- // drop the window. That closes it, and results in `Destroyed` being
69
- // sent.
70
- control_flow. set_exit ( ) ;
71
- }
64
+ // For a single-window application like this, you'd normally just
65
+ // break out of the event loop here. If you wanted to keep running the
66
+ // event loop (i.e. if it's a multi-window application), you need to
67
+ // drop the window. That closes it, and results in `Destroyed` being
68
+ // sent.
69
+ control_flow. set_exit ( ) ;
72
70
}
73
- Key :: Character ( "n" ) => {
74
- if close_requested {
75
- println ! ( "Your window will continue to stay by your side." ) ;
76
- close_requested = false ;
77
- }
71
+ }
72
+ Key :: Character ( "n" ) => {
73
+ if close_requested {
74
+ println ! ( "Your window will continue to stay by your side." ) ;
75
+ close_requested = false ;
78
76
}
79
- _ => ( ) ,
80
77
}
78
+ _ => ( ) ,
81
79
}
82
- _ => ( ) ,
83
80
}
81
+ WindowEvent :: RedrawRequested => {
82
+ fill:: fill_window ( & window) ;
83
+ }
84
+ _ => ( ) ,
84
85
}
85
- Event :: RedrawRequested ( _) => {
86
- fill:: fill_window ( & window) ;
87
- }
88
- _ => ( ) ,
89
86
}
90
87
} )
91
88
}
0 commit comments