Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobrand committed Jun 13, 2024
1 parent b71573c commit c916cb4
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 109 deletions.
4 changes: 3 additions & 1 deletion examples/raw-window-handle-with-wgpu/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
Expand Down
24 changes: 18 additions & 6 deletions src/sdl2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}
Expand Down
50 changes: 22 additions & 28 deletions src/sdl2/raw_window_handle.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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);
}

Expand Down Expand Up @@ -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")]
Expand All @@ -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)
}
Expand All @@ -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::<libc::c_void>::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",
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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::<libc::c_void>::new(a_native_window);
let a_native_window = match a_native_window {
Some(anw) => anw,
Expand All @@ -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 => {
Expand All @@ -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);
}

Expand All @@ -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)
}
Expand All @@ -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(
Expand All @@ -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)
}
Expand All @@ -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"))]
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
34 changes: 23 additions & 11 deletions src/sdl2/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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)))
);
}
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/sdl2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Loading

0 comments on commit c916cb4

Please sign in to comment.