From 52157c21f8c65af9e899c51645015648aa2152fb Mon Sep 17 00:00:00 2001 From: Osspial Date: Tue, 10 Mar 2020 16:12:43 -0400 Subject: [PATCH] Format --- examples/win32_modal_dialog.rs | 29 +++++++++++++++++++------ src/platform/windows.rs | 20 +++++++++++++---- src/platform_impl/windows/event_loop.rs | 18 +++++++-------- 3 files changed, 46 insertions(+), 21 deletions(-) diff --git a/examples/win32_modal_dialog.rs b/examples/win32_modal_dialog.rs index e865590cbf..c4aba62735 100644 --- a/examples/win32_modal_dialog.rs +++ b/examples/win32_modal_dialog.rs @@ -1,10 +1,10 @@ +use winapi::um::winuser; use winit::{ - event::{Event, KeyboardInput, WindowEvent, VirtualKeyCode, ElementState}, + event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, event_loop::{ControlFlow, EventLoop}, + platform::windows::{EventLoopWindowTargetExtWindows, WindowExtWindows}, window::WindowBuilder, - platform::windows::{WindowExtWindows, EventLoopWindowTargetExtWindows}, }; -use winapi::um::winuser; #[derive(Debug, Clone, Copy)] enum ModalDialogEvent { @@ -27,8 +27,23 @@ fn main() { println!("{:?}", event); match event { - Event::WindowEvent{ event: WindowEvent::CloseRequested, .. } | - Event::WindowEvent{ event: WindowEvent::KeyboardInput{ input: KeyboardInput{ virtual_keycode: Some(VirtualKeyCode::Escape), state: ElementState::Pressed, ..}, ..}, ..} => { + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } + | Event::WindowEvent { + event: + WindowEvent::KeyboardInput { + input: + KeyboardInput { + virtual_keycode: Some(VirtualKeyCode::Escape), + state: ElementState::Pressed, + .. + }, + .. + }, + .. + } => { let hwnd = window.hwnd(); let proxy = proxy.clone(); window_target.schedule_modal_fn(move || unsafe { @@ -38,7 +53,7 @@ fn main() { hwnd as _, "Are you sure you want close the window?\0".as_ptr() as *const _, "Confirm Close\0".as_ptr() as *const _, - winuser::MB_ICONEXCLAMATION | winuser::MB_YESNO + winuser::MB_ICONEXCLAMATION | winuser::MB_YESNO, ); println!("\n\t\tend modal loop\n"); @@ -47,7 +62,7 @@ fn main() { proxy.send_event(ModalDialogEvent::CloseWindow).unwrap(); } }); - }, + } Event::UserEvent(ModalDialogEvent::CloseWindow) => { *control_flow = ControlFlow::Exit; } diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 20ee7eed81..f71cd2c9f2 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -12,7 +12,9 @@ use crate::{ event::{DeviceId, Event}, event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget}, monitor::MonitorHandle, - platform_impl::{EventLoop as WindowsEventLoop, WinIcon, EventLoopEmbedded as WindowsEventLoopEmbedded}, + platform_impl::{ + EventLoop as WindowsEventLoop, EventLoopEmbedded as WindowsEventLoopEmbedded, WinIcon, + }, window::{BadIcon, Icon, Window, WindowBuilder}, }; @@ -59,7 +61,12 @@ pub trait EventLoopExtWindows { /// TODO: REWRITE `exit_requested` and `resume_panic_if_necessary` as trait functions. fn run_embedded<'a, F>(self, event_handler: F) -> EventLoopEmbedded<'a, Self::UserEvent> where - F: 'a + FnMut(Event<'_, Self::UserEvent>, &EventLoopWindowTarget, &mut ControlFlow); + F: 'a + + FnMut( + Event<'_, Self::UserEvent>, + &EventLoopWindowTarget, + &mut ControlFlow, + ); } impl EventLoopExtWindows for EventLoop { @@ -90,10 +97,15 @@ impl EventLoopExtWindows for EventLoop { fn run_embedded<'a, F>(self, event_handler: F) -> EventLoopEmbedded<'a, Self::UserEvent> where - F: 'a + FnMut(Event<'_, Self::UserEvent>, &EventLoopWindowTarget, &mut ControlFlow) + F: 'a + + FnMut( + Event<'_, Self::UserEvent>, + &EventLoopWindowTarget, + &mut ControlFlow, + ), { EventLoopEmbedded { - p: self.event_loop.run_embedded(event_handler) + p: self.event_loop.run_embedded(event_handler), } } } diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 83918ec7e5..de7c9726a0 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -217,19 +217,14 @@ impl EventLoop { pub fn run_embedded<'a, F>(mut self, event_handler: F) -> EventLoopEmbedded<'a, T> where - F: 'a + FnMut(Event<'_, T>, &RootELW, &mut ControlFlow) + F: 'a + FnMut(Event<'_, T>, &RootELW, &mut ControlFlow), { - unsafe { - self.embedded_runner(event_handler) - } + unsafe { self.embedded_runner(event_handler) } } - unsafe fn embedded_runner<'a, F>( - &mut self, - mut event_handler: F - ) -> EventLoopEmbedded<'a, T> + unsafe fn embedded_runner<'a, F>(&mut self, mut event_handler: F) -> EventLoopEmbedded<'a, T> where - F: 'a + FnMut(Event<'_, T>, &RootELW, &mut ControlFlow) + F: 'a + FnMut(Event<'_, T>, &RootELW, &mut ControlFlow), { let window_target = self.window_target.clone(); let event_loop_windows_ptr = &*window_target as *const RootELW; @@ -276,7 +271,10 @@ impl EventLoopEmbedded<'_, T> { impl Drop for EventLoopEmbedded<'_, T> { fn drop(&mut self) { unsafe { - self.window_target.p.runner_shared.call_event_handler(Event::LoopDestroyed); + self.window_target + .p + .runner_shared + .call_event_handler(Event::LoopDestroyed); self.window_target.p.runner_shared.reset_runner(); } }