diff --git a/examples/raw-window-handle-with-wgpu/main.rs b/examples/raw-window-handle-with-wgpu/main.rs index a14598da40..b5038449a6 100644 --- a/examples/raw-window-handle-with-wgpu/main.rs +++ b/examples/raw-window-handle-with-wgpu/main.rs @@ -30,7 +30,9 @@ fn main() -> Result<(), String> { ..Default::default() }); let surface = unsafe { - match instance.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window).unwrap()) { + match instance + .create_surface_unsafe(wgpu::SurfaceTargetUnsafe::from_window(&window).unwrap()) + { Ok(s) => s, Err(e) => return Err(e.to_string()), } diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index c572b7397e..6ad9c0fd79 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -681,7 +681,7 @@ pub enum Event { /// The X position of the mouse from the window's origin mouse_x: i32, /// The X position of the mouse from the window's origin - mouse_y: i32 + mouse_y: i32, }, JoyAxisMotion { @@ -1214,7 +1214,7 @@ impl Event { precise_x, precise_y, mouse_x, - mouse_y + mouse_y, } => { let event = sys::SDL_MouseWheelEvent { type_: SDL_EventType::SDL_MOUSEWHEEL as u32, @@ -2399,10 +2399,22 @@ impl Event { const SDL_TOUCH_MOUSEID: u32 = 0xFFFFFFFF; match self { - Self::MouseMotion { which: SDL_TOUCH_MOUSEID, .. } - | Self::MouseButtonDown { which: SDL_TOUCH_MOUSEID, .. } - | Self::MouseButtonUp { which: SDL_TOUCH_MOUSEID, .. } - | Self::MouseWheel { which: SDL_TOUCH_MOUSEID, .. } => true, + Self::MouseMotion { + which: SDL_TOUCH_MOUSEID, + .. + } + | Self::MouseButtonDown { + which: SDL_TOUCH_MOUSEID, + .. + } + | Self::MouseButtonUp { + which: SDL_TOUCH_MOUSEID, + .. + } + | Self::MouseWheel { + which: SDL_TOUCH_MOUSEID, + .. + } => true, _ => false, } } diff --git a/src/sdl2/raw_window_handle.rs b/src/sdl2/raw_window_handle.rs index 91c0b3c6a9..7ed209a1e6 100644 --- a/src/sdl2/raw_window_handle.rs +++ b/src/sdl2/raw_window_handle.rs @@ -1,8 +1,8 @@ extern crate raw_window_handle; use self::raw_window_handle::{ - RawDisplayHandle, RawWindowHandle, - HasWindowHandle, HasDisplayHandle, DisplayHandle, WindowHandle, HandleError + DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle, + RawWindowHandle, WindowHandle, }; use crate::{sys::SDL_Window, video::Window}; @@ -16,7 +16,7 @@ impl HasWindowHandle for Window { use self::raw_window_handle::WebWindowHandle; let handle = WebWindowHandle::new(1); let handle = RawWindowHandle::Web(handle); - let handle = unsafe{WindowHandle::borrow_raw(handle)}; + let handle = unsafe { WindowHandle::borrow_raw(handle) }; return Ok(handle); } @@ -50,7 +50,7 @@ impl HasWindowHandle for Window { handle.hinstance = hinstance; let handle = RawWindowHandle::Win32(handle); - let handle = unsafe {WindowHandle::borrow_raw(handle)}; + let handle = unsafe { WindowHandle::borrow_raw(handle) }; Ok(handle) } #[cfg(target_os = "windows")] @@ -67,7 +67,7 @@ impl HasWindowHandle for Window { }; let handle = WinRtWindowHandle::new(core_window); let handle = RawWindowHandle::WinRt(handle); - let handle = unsafe {WindowHandle::borrow_raw(handle)}; + let handle = unsafe { WindowHandle::borrow_raw(handle) }; Ok(handle) } @@ -81,21 +81,18 @@ impl HasWindowHandle for Window { SDL_SYSWM_WAYLAND => { use self::raw_window_handle::WaylandWindowHandle; - let surf = unsafe {wm_info.info.wl}.surface as *mut libc::c_void; + let surf = unsafe { wm_info.info.wl }.surface as *mut libc::c_void; let surf = core::ptr::NonNull::::new(surf); match surf { Some(surf) => { let handle = WaylandWindowHandle::new(surf); let handle = RawWindowHandle::Wayland(handle); - let handle = unsafe {WindowHandle::borrow_raw(handle)}; + let handle = unsafe { WindowHandle::borrow_raw(handle) }; Ok(handle) } - None => { - Err(HandleError::Unavailable) - } + None => Err(HandleError::Unavailable), } - } #[cfg(any( target_os = "linux", @@ -110,7 +107,7 @@ impl HasWindowHandle for Window { let window = unsafe { wm_info.info.x11 }.window; let xlib_handle = XlibWindowHandle::new(window); let raw_handle = RawWindowHandle::Xlib(xlib_handle); - let handle = unsafe{WindowHandle::borrow_raw(raw_handle)}; + let handle = unsafe { WindowHandle::borrow_raw(raw_handle) }; Ok(handle) } @@ -125,10 +122,10 @@ impl HasWindowHandle for Window { panic!("metal_view not initialized, please call WindowBuilder::metal_view() when building the window"); } }; - + let handle = AppKitWindowHandle::new(ns_view); let handle = RawWindowHandle::AppKit(handle); - let handle = unsafe {WindowHandle::borrow_raw(handle)}; + let handle = unsafe { WindowHandle::borrow_raw(handle) }; Ok(handle) } @@ -150,15 +147,14 @@ impl HasWindowHandle for Window { // Someone with an IOS device please test let handle = UiKitWindowHandle::new(ui_window); let handle = RawWindowHandle::UiKit(handle); - let handle = unsafe {WindowHandle::borrow_raw(handle)}; + let handle = unsafe { WindowHandle::borrow_raw(handle) }; Ok(handle) } #[cfg(any(target_os = "android"))] SDL_SYSWM_ANDROID => { use self::raw_window_handle::AndroidNdkWindowHandle; - let a_native_window = - unsafe { wm_info.info.android }.window as *mut libc::c_void; + let a_native_window = unsafe { wm_info.info.android }.window as *mut libc::c_void; let a_native_window = core::ptr::NonNull::::new(a_native_window); let a_native_window = match a_native_window { Some(anw) => anw, @@ -168,7 +164,7 @@ impl HasWindowHandle for Window { }; let handle = AndroidNdkWindowHandle::new(a_native_window); let handle = RawWindowHandle::AndroidNdk(handle); - let handle = unsafe{WindowHandle::borrow_raw(handle)}; + let handle = unsafe { WindowHandle::borrow_raw(handle) }; Ok(handle) } x => { @@ -195,7 +191,7 @@ impl HasDisplayHandle for Window { use self::raw_window_handle::WebDisplayHandle; let handle = WebDisplayHandle::new(); let handle = RawDisplayHandle::Web(handle); - let handle = unsafe{DisplayHandle::borrow_raw(handle)}; + let handle = unsafe { DisplayHandle::borrow_raw(handle) }; return Ok(handle); } @@ -217,7 +213,7 @@ impl HasDisplayHandle for Window { let handle = WindowsDisplayHandle::new(); let handle = RawDisplayHandle::Windows(handle); - let handle = unsafe {DisplayHandle::borrow_raw(handle)}; + let handle = unsafe { DisplayHandle::borrow_raw(handle) }; Ok(handle) } @@ -237,12 +233,10 @@ impl HasDisplayHandle for Window { Some(display) => { let mut handle = WaylandDisplayHandle::new(display); let handle = RawDisplayHandle::Wayland(handle); - let handle = unsafe{DisplayHandle::borrow_raw(handle)}; + let handle = unsafe { DisplayHandle::borrow_raw(handle) }; Ok(handle) } - None => { - Err(HandleError::Unavailable) - } + None => Err(HandleError::Unavailable), } } #[cfg(any( @@ -260,7 +254,7 @@ impl HasDisplayHandle for Window { let window = unsafe { wm_info.info.x11 }.window as i32; let handle = XlibDisplayHandle::new(display, window); let handle = RawDisplayHandle::Xlib(handle); - let handle = unsafe {DisplayHandle::borrow_raw(handle)}; + let handle = unsafe { DisplayHandle::borrow_raw(handle) }; Ok(handle) } @@ -269,7 +263,7 @@ impl HasDisplayHandle for Window { use self::raw_window_handle::AppKitDisplayHandle; let handle = AppKitDisplayHandle::new(); let handle = RawDisplayHandle::AppKit(handle); - let handle = unsafe {DisplayHandle::borrow_raw(handle)}; + let handle = unsafe { DisplayHandle::borrow_raw(handle) }; Ok(handle) } #[cfg(any(target_os = "ios"))] @@ -278,7 +272,7 @@ impl HasDisplayHandle for Window { let handle = UiKitDisplayHandle::new(); let handle = RawDisplayHandle::UiKit(handle); - let handle = unsafe {DisplayHandle::borrow_raw(handle)}; + let handle = unsafe { DisplayHandle::borrow_raw(handle) }; Ok(handle) } @@ -288,7 +282,7 @@ impl HasDisplayHandle for Window { let handle = AndroidDisplayHandle::new(); let handle = RawDisplayHandle::Android(handle); - let handle = unsafe {DisplayHandle::borrow_raw(handle)}; + let handle = unsafe { DisplayHandle::borrow_raw(handle) }; Ok(handle) } diff --git a/src/sdl2/rect.rs b/src/sdl2/rect.rs index 4c5600b6c1..aa3a9bf183 100644 --- a/src/sdl2/rect.rs +++ b/src/sdl2/rect.rs @@ -1681,10 +1681,7 @@ impl FPoint { /// Creates a new point from the given coordinates. pub fn new(x: f32, y: f32) -> FPoint { FPoint { - raw: sys::SDL_FPoint { - x, - y, - }, + raw: sys::SDL_FPoint { x, y }, } } @@ -1805,7 +1802,7 @@ impl std::iter::Sum for FPoint { #[cfg(test)] mod test { - use super::{max_int_value, min_int_value, Point, Rect, FPoint, FRect}; + use super::{max_int_value, min_int_value, FPoint, FRect, Point, Rect}; /// Used to compare "literal" (unclamped) rect values. fn tuple(x: i32, y: i32, w: u32, h: u32) -> (i32, i32, u32, u32) { @@ -2077,7 +2074,10 @@ mod test { #[test] fn frect_intersection() { let rect = FRect::new(0.0, 0.0, 10.0, 10.0); - assert_eq!(rect & FRect::new(9.0, 9.0, 10.0, 10.0), Some(FRect::new(9.0, 9.0, 1.0, 1.0))); + assert_eq!( + rect & FRect::new(9.0, 9.0, 10.0, 10.0), + Some(FRect::new(9.0, 9.0, 1.0, 1.0)) + ); assert_eq!(rect & FRect::new(11.0, 11.0, 10.0, 10.0), None); } @@ -2092,7 +2092,8 @@ mod test { #[test] fn frect_intersect_line() { assert_eq!( - FRect::new(1.0, 1.0, 5.0, 5.0).intersect_line(FPoint::new(0.0, 0.0), FPoint::new(10.0, 10.0)), + FRect::new(1.0, 1.0, 5.0, 5.0) + .intersect_line(FPoint::new(0.0, 0.0), FPoint::new(10.0, 10.0)), Some((FPoint::new(1.0, 1.0), FPoint::new(5.0, 5.0))) ); } @@ -2116,7 +2117,10 @@ mod test { #[test] fn frect_from() { - assert_eq!(FRect::from((-11.0, 5.0, 50.0, 20.0)), FRect::new(-11.0, 5.0, 50.0, 20.0)); + assert_eq!( + FRect::from((-11.0, 5.0, 50.0, 20.0)), + FRect::new(-11.0, 5.0, 50.0, 20.0) + ); } #[test] @@ -2133,7 +2137,10 @@ mod test { #[test] fn fpoint_add() { - assert_eq!(FPoint::new(-5.0, 7.0), FPoint::new(-11.0, 5.0) + FPoint::new(6.0, 2.0)); + assert_eq!( + FPoint::new(-5.0, 7.0), + FPoint::new(-11.0, 5.0) + FPoint::new(6.0, 2.0) + ); } #[test] @@ -2145,7 +2152,10 @@ mod test { #[test] fn fpoint_sub() { - assert_eq!(FPoint::new(-17.0, 3.0), FPoint::new(-11.0, 5.0) - FPoint::new(6.0, 2.0)); + assert_eq!( + FPoint::new(-17.0, 3.0), + FPoint::new(-11.0, 5.0) - FPoint::new(6.0, 2.0) + ); } #[test] @@ -2181,7 +2191,9 @@ mod test { #[test] fn fpoint_sum() { - let points_sum: FPoint = vec![FPoint::new(-11.0, 5.0), FPoint::new(6.0, 2.0)].into_iter().sum(); + let points_sum: FPoint = vec![FPoint::new(-11.0, 5.0), FPoint::new(6.0, 2.0)] + .into_iter() + .sum(); assert_eq!(FPoint::new(-5.0, 7.0), points_sum); } } diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 6288b7e63a..96abd52422 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -32,10 +32,10 @@ use crate::common::{validate_int, IntegerOrSdlError}; use crate::get_error; use crate::pixels; use crate::pixels::PixelFormatEnum; -use crate::rect::Point; -use crate::rect::Rect; use crate::rect::FPoint; use crate::rect::FRect; +use crate::rect::Point; +use crate::rect::Rect; use crate::surface; use crate::surface::{Surface, SurfaceContext, SurfaceRef}; use crate::video::{Window, WindowContext}; diff --git a/tests/raw_window_handle.rs b/tests/raw_window_handle.rs index 373fd1db81..9ebb536086 100644 --- a/tests/raw_window_handle.rs +++ b/tests/raw_window_handle.rs @@ -13,17 +13,19 @@ mod raw_window_handle_test { fn get_windows_handle() { let window = new_hidden_window(); match window.window_handle() { - Ok(window_handle) => { - match window_handle.as_raw() { - RawWindowHandle::Win32(_) => { - println!("Successfully received Win32 window handle") - }, - RawWindowHandle::WinRt(_) => { - println!("Successfully received WinRt window handle") - } - raw_handle => { - assert!(false, "Wrong window handle type for Windows: {:?}", raw_handle) - } + Ok(window_handle) => match window_handle.as_raw() { + RawWindowHandle::Win32(_) => { + println!("Successfully received Win32 window handle") + } + RawWindowHandle::WinRt(_) => { + println!("Successfully received WinRt window handle") + } + raw_handle => { + assert!( + false, + "Wrong window handle type for Windows: {:?}", + raw_handle + ) } }, Err(e) => { @@ -31,18 +33,24 @@ mod raw_window_handle_test { } } match window.display_handle() { - Ok(display_handle) => { - match display_handle.as_raw() { - RawDisplayHandle::Windows(_) => { - println!("Successfully received Windows display handle") - }, - raw_handle => { - assert!(false, "Wrong display handle type for Windows: {:?}", raw_handle) - } + Ok(display_handle) => match display_handle.as_raw() { + RawDisplayHandle::Windows(_) => { + println!("Successfully received Windows display handle") + } + raw_handle => { + assert!( + false, + "Wrong display handle type for Windows: {:?}", + raw_handle + ) } }, Err(e) => { - assert!(false, "Failed to recieve display handle on Windows: {:?}", e) + assert!( + false, + "Failed to recieve display handle on Windows: {:?}", + e + ) } } } @@ -58,17 +66,19 @@ mod raw_window_handle_test { fn get_linux_handle() { let window = new_hidden_window(); match window.window_handle() { - Ok(handle) => { - match handle.as_raw() { - RawWindowHandle::Xlib(_) => { - println!("Successfully received X11 window handle") - } - RawWindowHandle::Wayland(_) => { - println!("Successfully received Wayland window handle") - } - raw_handle => { - assert!(false, "Wrong window handle type for Linux: {:?}", raw_handle) - } + Ok(handle) => match handle.as_raw() { + RawWindowHandle::Xlib(_) => { + println!("Successfully received X11 window handle") + } + RawWindowHandle::Wayland(_) => { + println!("Successfully received Wayland window handle") + } + raw_handle => { + assert!( + false, + "Wrong window handle type for Linux: {:?}", + raw_handle + ) } }, Err(e) => { @@ -76,22 +86,24 @@ mod raw_window_handle_test { } } match window.display_handle() { - Ok(handle) => { - match handle.as_raw() { - RawDisplayHandle::Xlib(_) => { - println!("Successfully recieved X11 display handle") - } - RawDisplayHandle::Wayland(_) => { - println!("Successfully recieved Wayland display handle") - } - raw_handle => { - assert!(false, "Wrong display handle type for Linux: {:?}", raw_handle) - } + Ok(handle) => match handle.as_raw() { + RawDisplayHandle::Xlib(_) => { + println!("Successfully recieved X11 display handle") } - } + RawDisplayHandle::Wayland(_) => { + println!("Successfully recieved Wayland display handle") + } + raw_handle => { + assert!( + false, + "Wrong display handle type for Linux: {:?}", + raw_handle + ) + } + }, Err(e) => { assert!(false, "Failed to recieve display handle on Linux: {:?}", e) - }, + } } } @@ -100,29 +112,33 @@ mod raw_window_handle_test { fn get_macos_handle() { let window = new_hidden_window(); match window.window_handle() { - Ok(handle) => { - match handle.as_raw() { - RawWindowHandle::AppKit(_) => { - println!("Successfully recieved AppKit window handle") - } - raw_handle => { - assert!(false, "Wrong window handle type for macOS: {:?}", raw_handle) - } + Ok(handle) => match handle.as_raw() { + RawWindowHandle::AppKit(_) => { + println!("Successfully recieved AppKit window handle") } - } + raw_handle => { + assert!( + false, + "Wrong window handle type for macOS: {:?}", + raw_handle + ) + } + }, Err(e) => { assert!(false, "Failed to recieve window handle on macOS: {:?}", e) } }; match window.display_handle() { - Ok(handle) => { - match handle.as_raw(){ - RawDisplayHandle::AppKit(_) => { - println!("Successfully recieved AppKit display handle") - } - raw_handle => { - assert!(false, "Wrong display handle type for macOS: {:?}", raw_handle) - } + Ok(handle) => match handle.as_raw() { + RawDisplayHandle::AppKit(_) => { + println!("Successfully recieved AppKit display handle") + } + raw_handle => { + assert!( + false, + "Wrong display handle type for macOS: {:?}", + raw_handle + ) } }, Err(e) => {