Skip to content

Commit 52157c2

Browse files
committed
Format
1 parent c04ace5 commit 52157c2

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

examples/win32_modal_dialog.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use winapi::um::winuser;
12
use winit::{
2-
event::{Event, KeyboardInput, WindowEvent, VirtualKeyCode, ElementState},
3+
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
34
event_loop::{ControlFlow, EventLoop},
5+
platform::windows::{EventLoopWindowTargetExtWindows, WindowExtWindows},
46
window::WindowBuilder,
5-
platform::windows::{WindowExtWindows, EventLoopWindowTargetExtWindows},
67
};
7-
use winapi::um::winuser;
88

99
#[derive(Debug, Clone, Copy)]
1010
enum ModalDialogEvent {
@@ -27,8 +27,23 @@ fn main() {
2727
println!("{:?}", event);
2828

2929
match event {
30-
Event::WindowEvent{ event: WindowEvent::CloseRequested, .. } |
31-
Event::WindowEvent{ event: WindowEvent::KeyboardInput{ input: KeyboardInput{ virtual_keycode: Some(VirtualKeyCode::Escape), state: ElementState::Pressed, ..}, ..}, ..} => {
30+
Event::WindowEvent {
31+
event: WindowEvent::CloseRequested,
32+
..
33+
}
34+
| Event::WindowEvent {
35+
event:
36+
WindowEvent::KeyboardInput {
37+
input:
38+
KeyboardInput {
39+
virtual_keycode: Some(VirtualKeyCode::Escape),
40+
state: ElementState::Pressed,
41+
..
42+
},
43+
..
44+
},
45+
..
46+
} => {
3247
let hwnd = window.hwnd();
3348
let proxy = proxy.clone();
3449
window_target.schedule_modal_fn(move || unsafe {
@@ -38,7 +53,7 @@ fn main() {
3853
hwnd as _,
3954
"Are you sure you want close the window?\0".as_ptr() as *const _,
4055
"Confirm Close\0".as_ptr() as *const _,
41-
winuser::MB_ICONEXCLAMATION | winuser::MB_YESNO
56+
winuser::MB_ICONEXCLAMATION | winuser::MB_YESNO,
4257
);
4358

4459
println!("\n\t\tend modal loop\n");
@@ -47,7 +62,7 @@ fn main() {
4762
proxy.send_event(ModalDialogEvent::CloseWindow).unwrap();
4863
}
4964
});
50-
},
65+
}
5166
Event::UserEvent(ModalDialogEvent::CloseWindow) => {
5267
*control_flow = ControlFlow::Exit;
5368
}

src/platform/windows.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::{
1212
event::{DeviceId, Event},
1313
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
1414
monitor::MonitorHandle,
15-
platform_impl::{EventLoop as WindowsEventLoop, WinIcon, EventLoopEmbedded as WindowsEventLoopEmbedded},
15+
platform_impl::{
16+
EventLoop as WindowsEventLoop, EventLoopEmbedded as WindowsEventLoopEmbedded, WinIcon,
17+
},
1618
window::{BadIcon, Icon, Window, WindowBuilder},
1719
};
1820

@@ -59,7 +61,12 @@ pub trait EventLoopExtWindows {
5961
/// TODO: REWRITE `exit_requested` and `resume_panic_if_necessary` as trait functions.
6062
fn run_embedded<'a, F>(self, event_handler: F) -> EventLoopEmbedded<'a, Self::UserEvent>
6163
where
62-
F: 'a + FnMut(Event<'_, Self::UserEvent>, &EventLoopWindowTarget<Self::UserEvent>, &mut ControlFlow);
64+
F: 'a
65+
+ FnMut(
66+
Event<'_, Self::UserEvent>,
67+
&EventLoopWindowTarget<Self::UserEvent>,
68+
&mut ControlFlow,
69+
);
6370
}
6471

6572
impl<T> EventLoopExtWindows for EventLoop<T> {
@@ -90,10 +97,15 @@ impl<T> EventLoopExtWindows for EventLoop<T> {
9097

9198
fn run_embedded<'a, F>(self, event_handler: F) -> EventLoopEmbedded<'a, Self::UserEvent>
9299
where
93-
F: 'a + FnMut(Event<'_, Self::UserEvent>, &EventLoopWindowTarget<Self::UserEvent>, &mut ControlFlow)
100+
F: 'a
101+
+ FnMut(
102+
Event<'_, Self::UserEvent>,
103+
&EventLoopWindowTarget<Self::UserEvent>,
104+
&mut ControlFlow,
105+
),
94106
{
95107
EventLoopEmbedded {
96-
p: self.event_loop.run_embedded(event_handler)
108+
p: self.event_loop.run_embedded(event_handler),
97109
}
98110
}
99111
}

src/platform_impl/windows/event_loop.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,14 @@ impl<T: 'static> EventLoop<T> {
217217

218218
pub fn run_embedded<'a, F>(mut self, event_handler: F) -> EventLoopEmbedded<'a, T>
219219
where
220-
F: 'a + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow)
220+
F: 'a + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
221221
{
222-
unsafe {
223-
self.embedded_runner(event_handler)
224-
}
222+
unsafe { self.embedded_runner(event_handler) }
225223
}
226224

227-
unsafe fn embedded_runner<'a, F>(
228-
&mut self,
229-
mut event_handler: F
230-
) -> EventLoopEmbedded<'a, T>
225+
unsafe fn embedded_runner<'a, F>(&mut self, mut event_handler: F) -> EventLoopEmbedded<'a, T>
231226
where
232-
F: 'a + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow)
227+
F: 'a + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
233228
{
234229
let window_target = self.window_target.clone();
235230
let event_loop_windows_ptr = &*window_target as *const RootELW<T>;
@@ -276,7 +271,10 @@ impl<T> EventLoopEmbedded<'_, T> {
276271
impl<T> Drop for EventLoopEmbedded<'_, T> {
277272
fn drop(&mut self) {
278273
unsafe {
279-
self.window_target.p.runner_shared.call_event_handler(Event::LoopDestroyed);
274+
self.window_target
275+
.p
276+
.runner_shared
277+
.call_event_handler(Event::LoopDestroyed);
280278
self.window_target.p.runner_shared.reset_runner();
281279
}
282280
}

0 commit comments

Comments
 (0)