From c5394ed23a4b19d545f13fb44510acd6a4c86ba7 Mon Sep 17 00:00:00 2001 From: Elabajaba Date: Thu, 19 Dec 2024 21:03:16 -0500 Subject: [PATCH] cargo fmt (#61) --- examples/audio-capture-and-replay.rs | 48 +++--- examples/audio-squarewave.rs | 13 +- examples/audio-wav.rs | 1 - examples/audio-whitenoise.rs | 19 ++- examples/dialog.rs | 81 ++++++---- examples/filesystem.rs | 17 +-- examples/game-controller.rs | 3 +- examples/haptic.rs | 3 +- examples/joystick.rs | 11 +- examples/raw-window-handle-with-wgpu/main.rs | 23 +-- examples/renderer-target.rs | 21 +-- examples/renderer-texture.rs | 6 +- examples/renderer-yuv.rs | 6 +- src/sdl3/audio.rs | 2 +- src/sdl3/cpuinfo.rs | 2 +- src/sdl3/event.rs | 149 ++++++++++--------- src/sdl3/gamepad.rs | 2 +- src/sdl3/hint.rs | 4 +- src/sdl3/lib.rs | 7 +- src/sdl3/messagebox.rs | 4 +- src/sdl3/mouse/mod.rs | 8 +- src/sdl3/mouse/relative.rs | 6 +- src/sdl3/pixels.rs | 22 ++- src/sdl3/raw_window_handle.rs | 4 +- src/sdl3/rect.rs | 9 +- src/sdl3/render.rs | 8 +- src/sdl3/sdl.rs | 37 +---- src/sdl3/sensor.rs | 1 - src/sdl3/surface.rs | 15 +- src/sdl3/url.rs | 1 - src/sdl3/video.rs | 4 +- tests/raw_window_handle.rs | 14 +- 32 files changed, 292 insertions(+), 259 deletions(-) diff --git a/examples/audio-capture-and-replay.rs b/examples/audio-capture-and-replay.rs index e511636504..5da3c6e3a2 100644 --- a/examples/audio-capture-and-replay.rs +++ b/examples/audio-capture-and-replay.rs @@ -37,10 +37,7 @@ impl AudioCallback for Recording { } } -fn record( - audio_subsystem: &AudioSubsystem, - desired_spec: &AudioSpec, -) -> Result, String> { +fn record(audio_subsystem: &AudioSubsystem, desired_spec: &AudioSpec) -> Result, String> { println!( "Capturing {:} seconds... Please rock!", RECORDING_LENGTH_SECONDS @@ -48,22 +45,22 @@ fn record( let (done_sender, done_receiver) = mpsc::channel(); - let capture_device = audio_subsystem.open_recording_stream(desired_spec, Recording { - record_buffer: vec![ - 0; - desired_spec.freq.unwrap() as usize - * RECORDING_LENGTH_SECONDS - * desired_spec.channels.unwrap() as usize - ], - pos: 0, - done_sender, - done: false, - })?; - - println!( - "AudioDriver: {:?}", - audio_subsystem.current_audio_driver() - ); + let capture_device = audio_subsystem.open_recording_stream( + desired_spec, + Recording { + record_buffer: vec![ + 0; + desired_spec.freq.unwrap() as usize + * RECORDING_LENGTH_SECONDS + * desired_spec.channels.unwrap() as usize + ], + pos: 0, + done_sender, + done: false, + }, + )?; + + println!("AudioDriver: {:?}", audio_subsystem.current_audio_driver()); capture_device.resume()?; // Wait until the recording is done. @@ -115,10 +112,13 @@ fn replay_recorded_vec( ) -> Result<(), String> { println!("Playing..."); - let playback_device = audio_subsystem.open_playback_stream(desired_spec, SoundPlayback { - data: recorded_vec, - pos: 0, - })?; + let playback_device = audio_subsystem.open_playback_stream( + desired_spec, + SoundPlayback { + data: recorded_vec, + pos: 0, + }, + )?; // Start playback playback_device.resume()?; diff --git a/examples/audio-squarewave.rs b/examples/audio-squarewave.rs index 8aecc17635..121fb108fd 100644 --- a/examples/audio-squarewave.rs +++ b/examples/audio-squarewave.rs @@ -33,11 +33,14 @@ fn main() -> Result<(), String> { format: None, }; - let device = audio_subsystem.open_playback_stream(&desired_spec, SquareWave { - phase_inc: 440.0 / desired_spec.freq.unwrap() as f32, - phase: 0.0, - volume: 0.25, - })?; + let device = audio_subsystem.open_playback_stream( + &desired_spec, + SquareWave { + phase_inc: 440.0 / desired_spec.freq.unwrap() as f32, + phase: 0.0, + volume: 0.25, + }, + )?; // Start playback device.resume()?; diff --git a/examples/audio-wav.rs b/examples/audio-wav.rs index f21f36c09a..95f32a4c82 100644 --- a/examples/audio-wav.rs +++ b/examples/audio-wav.rs @@ -86,4 +86,3 @@ fn main() -> Result<(), String> { Ok(()) } - diff --git a/examples/audio-whitenoise.rs b/examples/audio-whitenoise.rs index e85b35393e..d3dc67c97a 100644 --- a/examples/audio-whitenoise.rs +++ b/examples/audio-whitenoise.rs @@ -2,7 +2,10 @@ extern crate rand; extern crate sdl3; use sdl3::audio::{AudioCallback, AudioSpec}; -use std::{sync::{Arc, Mutex}, time::Duration}; +use std::{ + sync::{Arc, Mutex}, + time::Duration, +}; struct MyCallback { volume: Arc>, // it seems like AudioStreamWithCallback<> is supposed to have a lock() method which allows us to modify MyCallback, but that function no longer seems to exist @@ -12,10 +15,12 @@ impl AudioCallback for MyCallback { use self::rand::{thread_rng, Rng}; let mut rng = thread_rng(); - let Ok(volume) = self.volume.lock() else {return}; + let Ok(volume) = self.volume.lock() else { + return; + }; // Generate white noise for x in out.iter_mut() { - *x = (rng.gen_range(0.0 ..= 2.0) - 1.0) * *volume; + *x = (rng.gen_range(0.0..=2.0) - 1.0) * *volume; } } } @@ -33,7 +38,13 @@ fn main() -> Result<(), String> { // None: use default device let volume = Arc::new(Mutex::new(0.5)); - let device = audio_subsystem.open_playback_stream_with_callback(&device, &desired_spec, MyCallback { volume: volume.clone() })?; + let device = audio_subsystem.open_playback_stream_with_callback( + &device, + &desired_spec, + MyCallback { + volume: volume.clone(), + }, + )?; // Start playback device.resume()?; diff --git a/examples/dialog.rs b/examples/dialog.rs index 77e02b4a8b..0976ab8c93 100644 --- a/examples/dialog.rs +++ b/examples/dialog.rs @@ -1,6 +1,8 @@ extern crate sdl3; -use sdl3::dialog::{show_open_file_dialog, show_open_folder_dialog, show_save_file_dialog, DialogFileFilter}; +use sdl3::dialog::{ + show_open_file_dialog, show_open_folder_dialog, show_save_file_dialog, DialogFileFilter, +}; use sdl3::event::Event; use sdl3::keyboard::Keycode; use sdl3::pixels::Color; @@ -51,8 +53,11 @@ pub fn main() -> Result<(), String> { .. } => { break 'running; - }, - Event::KeyDown {keycode: Some(Keycode::O), ..} => { + } + Event::KeyDown { + keycode: Some(Keycode::O), + .. + } => { show_open_file_dialog( &filters, None::, @@ -68,32 +73,50 @@ pub fn main() -> Result<(), String> { } }; }), - ).unwrap_or_else(|e| panic!("Failed to show open file dialog: {e}")); - }, - Event::KeyDown {keycode: Some(Keycode::D), ..} => { - show_open_folder_dialog(Some(&default_path_path), false, canvas.window(), Box::new(|result, _| { - match result { - Ok(result) => { - println!("Folder: {result:?}"); - } - Err(error) => { - eprintln!("Folder dialog error {error}"); - } - }; - })); - }, - Event::KeyDown {keycode: Some(Keycode::S), ..} => { - show_save_file_dialog(&filters, Some("/home"), canvas.window(), Box::new(|result, filter| { - match result { - Ok(result) => { - println!("Save File: {result:?} Filter: {filter:?}"); - } - Err(error) => { - eprintln!("Save dialog error {error}"); - } - }; - })).unwrap_or_else(|e| panic!("Failed to show save file dialog: {e}")); - }, + ) + .unwrap_or_else(|e| panic!("Failed to show open file dialog: {e}")); + } + Event::KeyDown { + keycode: Some(Keycode::D), + .. + } => { + show_open_folder_dialog( + Some(&default_path_path), + false, + canvas.window(), + Box::new(|result, _| { + match result { + Ok(result) => { + println!("Folder: {result:?}"); + } + Err(error) => { + eprintln!("Folder dialog error {error}"); + } + }; + }), + ); + } + Event::KeyDown { + keycode: Some(Keycode::S), + .. + } => { + show_save_file_dialog( + &filters, + Some("/home"), + canvas.window(), + Box::new(|result, filter| { + match result { + Ok(result) => { + println!("Save File: {result:?} Filter: {filter:?}"); + } + Err(error) => { + eprintln!("Save dialog error {error}"); + } + }; + }), + ) + .unwrap_or_else(|e| panic!("Failed to show save file dialog: {e}")); + } _ => {} } } diff --git a/examples/filesystem.rs b/examples/filesystem.rs index d59cb3b85f..f4e5f6444b 100644 --- a/examples/filesystem.rs +++ b/examples/filesystem.rs @@ -10,11 +10,11 @@ pub fn main() -> Result<(), String> { let path_info = get_path_info(base_path).unwrap(); println!("Base path info: {path_info:?}"); - enumerate_directory(base_path, |directory, file| { println!("Enumerate {directory:?}: {file:?}"); return EnumerationResult::CONTINUE; - }).ok(); + }) + .ok(); if let Ok(results) = glob_directory(base_path, Some("filesystem*"), GlobFlags::NONE) { for result in &results { @@ -29,22 +29,22 @@ pub fn main() -> Result<(), String> { let test_path2 = base_path.join("testpath2"); match get_path_info(&test_path) { Ok(info) => println!("Test path info: {info:?}"), - Err(e) => println!("Test path error: {e:?}") + Err(e) => println!("Test path error: {e:?}"), } create_directory(&test_path).ok(); match get_path_info(&test_path) { Ok(info) => println!("Test path info: {info:?}"), - Err(e) => println!("Test path error: {e:?}") + Err(e) => println!("Test path error: {e:?}"), } match rename_path(&test_path, &test_path2) { Ok(()) => println!("Renamed {test_path:?} to {test_path2:?}"), - Err(e) => eprintln!("Failed to rename: {e:?}") + Err(e) => eprintln!("Failed to rename: {e:?}"), } match remove_path(&test_path2) { Ok(()) => println!("Removed {test_path2:?}"), - Err(e) => eprintln!("Failed to remove: {e:?}") + Err(e) => eprintln!("Failed to remove: {e:?}"), } match get_pref_path("sdl-rs", "filesystem") { @@ -52,14 +52,13 @@ pub fn main() -> Result<(), String> { println!("Got pref path for org 'sdl-rs' app 'filesystem' as {path:?}"); match remove_path(&path) { Ok(()) => println!("Removed {path:?}"), - Err(e) => eprintln!("Failed to remove: {e:?}") + Err(e) => eprintln!("Failed to remove: {e:?}"), } - }, + } Err(error) => { eprintln!("Failed to get pref path for org 'sdl-rs' app 'filesystem': {error:?}") } } - Ok(()) } diff --git a/examples/game-controller.rs b/examples/game-controller.rs index cb714a2771..99015a5f9c 100644 --- a/examples/game-controller.rs +++ b/examples/game-controller.rs @@ -17,7 +17,6 @@ fn main() -> Result<(), String> { // Iterate over all available joysticks and look for game controllers. let mut controller = (0..available) .find_map(|id| { - println!("Attempting to open gamepad {}", id); match gamepad_subsystem.open(id) { @@ -40,8 +39,8 @@ fn main() -> Result<(), String> { let (mut lo_freq, mut hi_freq) = (0, 0); for event in sdl_context.event_pump()?.wait_iter() { - use sdl3::gamepad::Axis; use sdl3::event::Event; + use sdl3::gamepad::Axis; match event { Event::ControllerAxisMotion { diff --git a/examples/haptic.rs b/examples/haptic.rs index 300466124f..4eb0ee6f84 100644 --- a/examples/haptic.rs +++ b/examples/haptic.rs @@ -12,7 +12,8 @@ fn main() -> Result<(), String> { println!("{} joysticks available", joysticks.len()); // Iterate over all available joysticks and stop once we manage to open one. - let (_joystick, joystick_id) = joysticks.into_iter() + let (_joystick, joystick_id) = joysticks + .into_iter() .find_map(|joystick| { let id = joystick.id; match joystick_subsystem.open(joystick) { diff --git a/examples/joystick.rs b/examples/joystick.rs index d0086b2599..c57fe5ba1e 100644 --- a/examples/joystick.rs +++ b/examples/joystick.rs @@ -13,7 +13,8 @@ fn main() -> Result<(), String> { println!("{} joysticks available", joysticks.len()); // Iterate over all available joysticks and stop once we manage to open one. - let mut joystick = joysticks.into_iter() + let mut joystick = joysticks + .into_iter() .find_map(|joystick| match joystick_subsystem.open(joystick) { Ok(c) => { println!("Success: opened \"{}\"", c.name()); @@ -65,7 +66,9 @@ fn main() -> Result<(), String> { } else { println!( "Error setting rumble to ({}, {}): {:?}", - lo_freq, hi_freq, get_error() + lo_freq, + hi_freq, + get_error() ); } } @@ -83,7 +86,9 @@ fn main() -> Result<(), String> { } else { println!( "Error setting rumble to ({}, {}): {:?}", - lo_freq, hi_freq, get_error() + lo_freq, + hi_freq, + get_error() ); } } diff --git a/examples/raw-window-handle-with-wgpu/main.rs b/examples/raw-window-handle-with-wgpu/main.rs index 192a8bd87b..a4898c554d 100644 --- a/examples/raw-window-handle-with-wgpu/main.rs +++ b/examples/raw-window-handle-with-wgpu/main.rs @@ -32,7 +32,9 @@ fn main() -> Result<(), String> { force_fallback_adapter: false, compatible_surface: Some(&surface), })); - let Some(adapter) = adapter_opt else {return Err(String::from("No adapter found"))}; + let Some(adapter) = adapter_opt else { + return Err(String::from("No adapter found")); + }; let (device, queue) = match pollster::block_on(adapter.request_device( &wgpu::DeviceDescriptor { @@ -49,7 +51,8 @@ fn main() -> Result<(), String> { let capabilities = surface.get_capabilities(&adapter); let mut formats = capabilities.formats; - let main_format = *formats.iter() + let main_format = *formats + .iter() .find(|format| format.is_srgb()) .unwrap_or(&formats[0]); @@ -119,7 +122,7 @@ fn main() -> Result<(), String> { present_mode: wgpu::PresentMode::Fifo, alpha_mode: wgpu::CompositeAlphaMode::Auto, desired_maximum_frame_latency: 0, - view_formats: vec!(), + view_formats: vec![], }; surface.configure(&device, &config); @@ -195,14 +198,12 @@ fn main() -> Result<(), String> { Ok(()) } - - mod create_surface { use sdl3::video::Window; use wgpu::rwh::{HasDisplayHandle, HasWindowHandle}; // contains the unsafe impl as much as possible by putting it in this module - struct SyncWindow<'a> (&'a Window); + struct SyncWindow<'a>(&'a Window); unsafe impl<'a> Send for SyncWindow<'a> {} unsafe impl<'a> Sync for SyncWindow<'a> {} @@ -218,8 +219,12 @@ mod create_surface { } } - pub fn create_surface<'a>(instance: &wgpu::Instance, window: &'a Window) -> Result, String> { - instance.create_surface(SyncWindow(&window)).map_err(|err| err.to_string()) + pub fn create_surface<'a>( + instance: &wgpu::Instance, + window: &'a Window, + ) -> Result, String> { + instance + .create_surface(SyncWindow(&window)) + .map_err(|err| err.to_string()) } - } diff --git a/examples/renderer-target.rs b/examples/renderer-target.rs index 696d74dfa6..16451027e6 100644 --- a/examples/renderer-target.rs +++ b/examples/renderer-target.rs @@ -17,7 +17,11 @@ fn main() -> Result<(), String> { let mut canvas = window.into_canvas(); let creator = canvas.texture_creator(); let mut texture = creator - .create_texture_target(unsafe {PixelFormat::from_ll(SDL_PixelFormat::RGBA8888)}, 400, 300) + .create_texture_target( + unsafe { PixelFormat::from_ll(SDL_PixelFormat::RGBA8888) }, + 400, + 300, + ) .map_err(|e| e.to_string())?; let mut angle = 0.0; @@ -34,14 +38,13 @@ fn main() -> Result<(), String> { } } angle = (angle + 0.5) % 360.; - canvas - .with_texture_canvas(&mut texture, |texture_canvas| { - texture_canvas.clear(); - texture_canvas.set_draw_color(Color::RGBA(255, 0, 0, 255)); - texture_canvas - .fill_rect(FRect::new(0.0, 0.0, 400.0, 300.0)) - .expect("could not fill rect"); - }); + canvas.with_texture_canvas(&mut texture, |texture_canvas| { + texture_canvas.clear(); + texture_canvas.set_draw_color(Color::RGBA(255, 0, 0, 255)); + texture_canvas + .fill_rect(FRect::new(0.0, 0.0, 400.0, 300.0)) + .expect("could not fill rect"); + }); canvas.set_draw_color(Color::RGBA(0, 0, 0, 255)); let dst = Some(FRect::new(0.0, 0.0, 400.0, 300.0)); canvas.clear(); diff --git a/examples/renderer-texture.rs b/examples/renderer-texture.rs index 2793de2866..1771a27a45 100644 --- a/examples/renderer-texture.rs +++ b/examples/renderer-texture.rs @@ -21,7 +21,11 @@ pub fn main() -> Result<(), String> { let texture_creator = canvas.texture_creator(); let mut texture = texture_creator - .create_texture_streaming(unsafe {PixelFormat::from_ll(SDL_PixelFormat::RGB24)}, 256, 256) + .create_texture_streaming( + unsafe { PixelFormat::from_ll(SDL_PixelFormat::RGB24) }, + 256, + 256, + ) .map_err(|e| e.to_string())?; // Create a red-green gradient texture.with_lock(None, |buffer: &mut [u8], pitch: usize| { diff --git a/examples/renderer-yuv.rs b/examples/renderer-yuv.rs index e137775302..73d925881a 100644 --- a/examples/renderer-yuv.rs +++ b/examples/renderer-yuv.rs @@ -21,7 +21,11 @@ pub fn main() -> Result<(), String> { let texture_creator = canvas.texture_creator(); let mut texture = texture_creator - .create_texture_streaming(unsafe {PixelFormat::from_ll(SDL_PixelFormat::IYUV)}, 256, 256) + .create_texture_streaming( + unsafe { PixelFormat::from_ll(SDL_PixelFormat::IYUV) }, + 256, + 256, + ) .map_err(|e| e.to_string())?; // Create a U-V gradient texture.with_lock(None, |buffer: &mut [u8], pitch: usize| { diff --git a/src/sdl3/audio.rs b/src/sdl3/audio.rs index a780e61c0c..5a1bed47b3 100644 --- a/src/sdl3/audio.rs +++ b/src/sdl3/audio.rs @@ -586,7 +586,7 @@ impl AudioSpec { } impl Default for AudioSpec { - /// Creates an `AudioSpec` with all fields set to `None` (use device defaults). + /// Creates an `AudioSpec` with all fields set to `None` (use device defaults). fn default() -> Self { Self { freq: None, diff --git a/src/sdl3/cpuinfo.rs b/src/sdl3/cpuinfo.rs index 4ec454035d..a4f04e8a31 100644 --- a/src/sdl3/cpuinfo.rs +++ b/src/sdl3/cpuinfo.rs @@ -90,4 +90,4 @@ pub fn system_ram() -> i32 { #[doc(alias = "SDL_GetSIMDAlignment")] pub fn simd_alignment() -> usize { unsafe { sys::cpuinfo::SDL_GetSIMDAlignment() } -} \ No newline at end of file +} diff --git a/src/sdl3/event.rs b/src/sdl3/event.rs index 5cf6db74a0..98fad3dd8b 100644 --- a/src/sdl3/event.rs +++ b/src/sdl3/event.rs @@ -116,10 +116,7 @@ impl crate::EventSubsystem { } else { events.set_len(result as usize); - events - .into_iter() - .map(Event::from_ll) - .collect() + events.into_iter().map(Event::from_ll).collect() } } } @@ -492,12 +489,13 @@ impl DisplayEvent { } pub fn is_same_kind_as(&self, other: &DisplayEvent) -> bool { - matches!((self, other), + matches!( + (self, other), (Self::None, Self::None) - | (Self::Orientation(_), Self::Orientation(_)) - | (Self::Added, Self::Added) - | (Self::Removed, Self::Removed) - ) + | (Self::Orientation(_), Self::Orientation(_)) + | (Self::Added, Self::Added) + | (Self::Removed, Self::Removed) + ) } } @@ -576,26 +574,27 @@ impl WindowEvent { } pub fn is_same_kind_as(&self, other: &WindowEvent) -> bool { - matches!((self, other), + matches!( + (self, other), (Self::None, Self::None) - | (Self::Shown, Self::Shown) - | (Self::Hidden, Self::Hidden) - | (Self::Exposed, Self::Exposed) - | (Self::Moved(_, _), Self::Moved(_, _)) - | (Self::Resized(_, _), Self::Resized(_, _)) - | (Self::PixelSizeChanged(_, _), Self::PixelSizeChanged(_, _)) - | (Self::Minimized, Self::Minimized) - | (Self::Maximized, Self::Maximized) - | (Self::Restored, Self::Restored) - | (Self::MouseEnter, Self::MouseEnter) - | (Self::MouseLeave, Self::MouseLeave) - | (Self::FocusGained, Self::FocusGained) - | (Self::FocusLost, Self::FocusLost) - | (Self::CloseRequested, Self::CloseRequested) - | (Self::HitTest(_, _), Self::HitTest(_, _)) - | (Self::ICCProfChanged, Self::ICCProfChanged) - | (Self::DisplayChanged(_), Self::DisplayChanged(_)) - ) + | (Self::Shown, Self::Shown) + | (Self::Hidden, Self::Hidden) + | (Self::Exposed, Self::Exposed) + | (Self::Moved(_, _), Self::Moved(_, _)) + | (Self::Resized(_, _), Self::Resized(_, _)) + | (Self::PixelSizeChanged(_, _), Self::PixelSizeChanged(_, _)) + | (Self::Minimized, Self::Minimized) + | (Self::Maximized, Self::Maximized) + | (Self::Restored, Self::Restored) + | (Self::MouseEnter, Self::MouseEnter) + | (Self::MouseLeave, Self::MouseLeave) + | (Self::FocusGained, Self::FocusGained) + | (Self::FocusLost, Self::FocusLost) + | (Self::CloseRequested, Self::CloseRequested) + | (Self::HitTest(_, _), Self::HitTest(_, _)) + | (Self::ICCProfChanged, Self::ICCProfChanged) + | (Self::DisplayChanged(_), Self::DisplayChanged(_)) + ) } } @@ -2253,16 +2252,17 @@ impl Event { /// assert!(another_ev.is_window() == false); // Not a window event! /// ``` pub fn is_window(&self) -> bool { - matches!(self, + matches!( + self, Self::Quit { .. } - | Self::AppTerminating { .. } - | Self::AppLowMemory { .. } - | Self::AppWillEnterBackground { .. } - | Self::AppDidEnterBackground { .. } - | Self::AppWillEnterForeground { .. } - | Self::AppDidEnterForeground { .. } - | Self::Window { .. } - ) + | Self::AppTerminating { .. } + | Self::AppLowMemory { .. } + | Self::AppWillEnterBackground { .. } + | Self::AppDidEnterBackground { .. } + | Self::AppWillEnterForeground { .. } + | Self::AppDidEnterForeground { .. } + | Self::Window { .. } + ) } /// Returns `true` if this is a keyboard event. @@ -2291,9 +2291,7 @@ impl Event { /// assert!(another_ev.is_keyboard() == false); // Not a keyboard event! /// ``` pub fn is_keyboard(&self) -> bool { - matches!(self, - Self::KeyDown { .. } | Self::KeyUp { .. } - ) + matches!(self, Self::KeyDown { .. } | Self::KeyUp { .. }) } /// Returns `true` if this is a text event. @@ -2316,9 +2314,7 @@ impl Event { /// assert!(another_ev.is_text() == false); // Not a text event! /// ``` pub fn is_text(&self) -> bool { - matches!(self, - Self::TextEditing { .. } | Self::TextInput { .. } - ) + matches!(self, Self::TextEditing { .. } | Self::TextInput { .. }) } /// Returns `true` if this is a mouse event. @@ -2347,12 +2343,13 @@ impl Event { /// assert!(another_ev.is_mouse() == false); // Not a mouse event! /// ``` pub fn is_mouse(&self) -> bool { - matches!(self, + matches!( + self, Self::MouseMotion { .. } - | Self::MouseButtonDown { .. } - | Self::MouseButtonUp { .. } - | Self::MouseWheel { .. } - ) + | Self::MouseButtonDown { .. } + | Self::MouseButtonUp { .. } + | Self::MouseWheel { .. } + ) } /// Returns `true` if this is a controller event. @@ -2374,14 +2371,15 @@ impl Event { /// assert!(another_ev.is_controller() == false); // Not a controller event! /// ``` pub fn is_controller(&self) -> bool { - matches!(self, + matches!( + self, Self::ControllerAxisMotion { .. } - | Self::ControllerButtonDown { .. } - | Self::ControllerButtonUp { .. } - | Self::ControllerDeviceAdded { .. } - | Self::ControllerDeviceRemoved { .. } - | Self::ControllerDeviceRemapped { .. } - ) + | Self::ControllerButtonDown { .. } + | Self::ControllerButtonUp { .. } + | Self::ControllerDeviceAdded { .. } + | Self::ControllerDeviceRemoved { .. } + | Self::ControllerDeviceRemapped { .. } + ) } /// Returns `true` if this is a joy event. @@ -2404,14 +2402,15 @@ impl Event { /// assert!(another_ev.is_joy() == false); // Not a joy event! /// ``` pub fn is_joy(&self) -> bool { - matches!(self, + matches!( + self, Self::JoyAxisMotion { .. } - | Self::JoyHatMotion { .. } - | Self::JoyButtonDown { .. } - | Self::JoyButtonUp { .. } - | Self::JoyDeviceAdded { .. } - | Self::JoyDeviceRemoved { .. } - ) + | Self::JoyHatMotion { .. } + | Self::JoyButtonDown { .. } + | Self::JoyButtonUp { .. } + | Self::JoyDeviceAdded { .. } + | Self::JoyDeviceRemoved { .. } + ) } /// Returns `true` if this is a finger event. @@ -2439,9 +2438,10 @@ impl Event { /// assert!(another_ev.is_finger() == false); // Not a finger event! /// ``` pub fn is_finger(&self) -> bool { - matches!(self, + matches!( + self, Self::FingerDown { .. } | Self::FingerUp { .. } | Self::FingerMotion { .. } - ) + ) } /// Returns `true` if this is a drop event. @@ -2463,12 +2463,13 @@ impl Event { /// assert!(another_ev.is_drop() == false); // Not a drop event! /// ``` pub fn is_drop(&self) -> bool { - matches!(self, + matches!( + self, Self::DropFile { .. } - | Self::DropText { .. } - | Self::DropBegin { .. } - | Self::DropComplete { .. } - ) + | Self::DropText { .. } + | Self::DropBegin { .. } + | Self::DropComplete { .. } + ) } /// Returns `true` if this is an audio event. @@ -2491,7 +2492,10 @@ impl Event { /// assert!(another_ev.is_audio() == false); // Not an audio event! /// ``` pub fn is_audio(&self) -> bool { - matches!(self, Self::AudioDeviceAdded { .. } | Self::AudioDeviceRemoved { .. }) + matches!( + self, + Self::AudioDeviceAdded { .. } | Self::AudioDeviceRemoved { .. } + ) } /// Returns `true` if this is a render event. @@ -2512,7 +2516,10 @@ impl Event { /// assert!(another_ev.is_render() == false); // Not a render event! /// ``` pub fn is_render(&self) -> bool { - matches!(self, Self::RenderTargetsReset { .. } | Self::RenderDeviceReset { .. }) + matches!( + self, + Self::RenderTargetsReset { .. } | Self::RenderDeviceReset { .. } + ) } /// Returns `true` if this is a user event. diff --git a/src/sdl3/gamepad.rs b/src/sdl3/gamepad.rs index d0eafd85a3..8d23b48d4f 100644 --- a/src/sdl3/gamepad.rs +++ b/src/sdl3/gamepad.rs @@ -14,11 +14,11 @@ use std::convert::TryInto; use crate::common::IntegerOrSdlError; use crate::get_error; +use crate::guid::Guid; use crate::sys; use crate::GamepadSubsystem; use std::mem::transmute; use sys::joystick::SDL_GetJoystickID; -use crate::guid::Guid; #[derive(Debug, Clone)] pub enum AddMappingError { diff --git a/src/sdl3/hint.rs b/src/sdl3/hint.rs index 31d3ce2c73..b929b10258 100644 --- a/src/sdl3/hint.rs +++ b/src/sdl3/hint.rs @@ -68,7 +68,9 @@ pub fn set_video_minimize_on_focus_loss_with_priority(value: bool, priority: &Hi /// assert_eq!(sdl3::hint::get_video_minimize_on_focus_loss(), false); /// ``` pub fn get_video_minimize_on_focus_loss() -> bool { - let Some(value) = get(VIDEO_MINIMIZE_ON_FOCUS_LOSS) else {return true;}; + let Some(value) = get(VIDEO_MINIMIZE_ON_FOCUS_LOSS) else { + return true; + }; &*value == "1" } diff --git a/src/sdl3/lib.rs b/src/sdl3/lib.rs index aa7b2a8791..804f3eaee5 100644 --- a/src/sdl3/lib.rs +++ b/src/sdl3/lib.rs @@ -47,7 +47,12 @@ #![crate_name = "sdl3"] #![crate_type = "lib"] -#![allow(clippy::cast_lossless, clippy::transmute_ptr_to_ref, clippy::missing_transmute_annotations, clippy::missing_safety_doc)] +#![allow( + clippy::cast_lossless, + clippy::transmute_ptr_to_ref, + clippy::missing_transmute_annotations, + clippy::missing_safety_doc +)] #[macro_use] extern crate bitflags; diff --git a/src/sdl3/messagebox.rs b/src/sdl3/messagebox.rs index 42a9e31a8b..9d9be1c474 100644 --- a/src/sdl3/messagebox.rs +++ b/src/sdl3/messagebox.rs @@ -43,9 +43,7 @@ pub struct MessageBoxColorScheme { impl From for sys::messagebox::SDL_MessageBoxColorScheme { fn from(val: MessageBoxColorScheme) -> Self { - sys::messagebox::SDL_MessageBoxColorScheme { - colors: val.into(), - } + sys::messagebox::SDL_MessageBoxColorScheme { colors: val.into() } } } diff --git a/src/sdl3/mouse/mod.rs b/src/sdl3/mouse/mod.rs index 509bc62598..a0a28eb5f8 100644 --- a/src/sdl3/mouse/mod.rs +++ b/src/sdl3/mouse/mod.rs @@ -1,9 +1,9 @@ -use std::convert::TryInto; use crate::get_error; use crate::surface::SurfaceRef; use crate::sys; use crate::video; use crate::EventPump; +use std::convert::TryInto; use std::mem::transmute; use sys::mouse::{ SDL_GetWindowRelativeMouseMode, SDL_MouseWheelDirection, SDL_SetWindowRelativeMouseMode, @@ -211,11 +211,7 @@ impl MouseState { let mut y = 0.; let mouse_state: u32 = unsafe { sys::mouse::SDL_GetMouseState(&mut x, &mut y) }; - MouseState { - mouse_state, - x, - y, - } + MouseState { mouse_state, x, y } } pub fn from_sdl_state(state: u32) -> MouseState { diff --git a/src/sdl3/mouse/relative.rs b/src/sdl3/mouse/relative.rs index 6283f195ca..0cb92d9987 100644 --- a/src/sdl3/mouse/relative.rs +++ b/src/sdl3/mouse/relative.rs @@ -21,11 +21,7 @@ impl RelativeMouseState { sys::mouse::SDL_GetRelativeMouseState(&mut x, &mut y) }; - RelativeMouseState { - mouse_state, - x, - y, - } + RelativeMouseState { mouse_state, x, y } } pub fn from_sdl_state(state: u32) -> RelativeMouseState { diff --git a/src/sdl3/pixels.rs b/src/sdl3/pixels.rs index 70fc3ed2a6..00cccb286f 100644 --- a/src/sdl3/pixels.rs +++ b/src/sdl3/pixels.rs @@ -1,6 +1,6 @@ use crate::get_error; use crate::sys; -use std::convert::{TryInto, TryFrom}; +use std::convert::{TryFrom, TryInto}; use std::ffi::c_int; use std::fmt::Debug; use std::ptr::null; @@ -239,7 +239,7 @@ impl Debug for PixelFormat { } impl PixelFormat { - pub unsafe fn unknown() -> PixelFormat { + pub unsafe fn unknown() -> PixelFormat { PixelFormat::from_ll(SDL_PixelFormat::UNKNOWN) } @@ -386,9 +386,21 @@ impl PixelFormat { } pub fn supports_alpha(self) -> bool { - matches!(self.raw, - SDL_PixelFormat::ARGB4444 | SDL_PixelFormat::ARGB1555 | SDL_PixelFormat::ARGB8888 | SDL_PixelFormat::ARGB2101010 | SDL_PixelFormat::ABGR4444 | SDL_PixelFormat::ABGR1555 | SDL_PixelFormat::ABGR8888 - | SDL_PixelFormat::BGRA4444 | SDL_PixelFormat::BGRA5551 | SDL_PixelFormat::BGRA8888 | SDL_PixelFormat::RGBA4444 | SDL_PixelFormat::RGBA5551 | SDL_PixelFormat::RGBA8888 + matches!( + self.raw, + SDL_PixelFormat::ARGB4444 + | SDL_PixelFormat::ARGB1555 + | SDL_PixelFormat::ARGB8888 + | SDL_PixelFormat::ARGB2101010 + | SDL_PixelFormat::ABGR4444 + | SDL_PixelFormat::ABGR1555 + | SDL_PixelFormat::ABGR8888 + | SDL_PixelFormat::BGRA4444 + | SDL_PixelFormat::BGRA5551 + | SDL_PixelFormat::BGRA8888 + | SDL_PixelFormat::RGBA4444 + | SDL_PixelFormat::RGBA5551 + | SDL_PixelFormat::RGBA8888 ) } } diff --git a/src/sdl3/raw_window_handle.rs b/src/sdl3/raw_window_handle.rs index 57e8c0a98c..4900589df2 100644 --- a/src/sdl3/raw_window_handle.rs +++ b/src/sdl3/raw_window_handle.rs @@ -2,7 +2,9 @@ extern crate raw_window_handle; use std::num::NonZero; -use self::raw_window_handle::{HandleError, HasDisplayHandle, HasWindowHandle, WindowHandle, DisplayHandle, RawWindowHandle}; +use self::raw_window_handle::{ + DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawWindowHandle, WindowHandle, +}; use sys::properties::SDL_GetPointerProperty; use crate::video::Window; diff --git a/src/sdl3/rect.rs b/src/sdl3/rect.rs index 2082cec1ff..6e1f7cb81d 100644 --- a/src/sdl3/rect.rs +++ b/src/sdl3/rect.rs @@ -433,10 +433,7 @@ impl Rect { /// If a clipping rectangle is given, only points that are within it will be /// considered. #[doc(alias = "SDL_GetRectEnclosingPoints")] - pub fn from_enclose_points( - points: &[Point], - clipping_rect: R, - ) -> Option + pub fn from_enclose_points(points: &[Point], clipping_rect: R) -> Option where R: Into>, { @@ -902,7 +899,7 @@ impl DivAssign for Point { } impl std::iter::Sum for Point { - fn sum>(iter: I) -> Self { + fn sum>(iter: I) -> Self { iter.fold(Point::new(0, 0), Point::add) } } @@ -953,7 +950,7 @@ mod test { ], None ) - .map(|r| r.into()) + .map(|r| r.into()) ); } diff --git a/src/sdl3/render.rs b/src/sdl3/render.rs index 5b2d3fce9c..5d1ff626f0 100644 --- a/src/sdl3/render.rs +++ b/src/sdl3/render.rs @@ -1018,9 +1018,8 @@ impl Canvas { /// Sets the blend mode used for drawing operations (Fill and Line). #[doc(alias = "SDL_SetRenderDrawBlendMode")] pub fn set_blend_mode(&mut self, blend: BlendMode) { - let ret = unsafe { - sys::render::SDL_SetRenderDrawBlendMode(self.context.raw, blend as u32) - }; + let ret = + unsafe { sys::render::SDL_SetRenderDrawBlendMode(self.context.raw, blend as u32) }; // Should only fail on an invalid renderer if !ret { panic!("{}", get_error()) @@ -1942,8 +1941,7 @@ impl InternalTexture { #[doc(alias = "SDL_SetTextureBlendMode")] pub fn set_blend_mode(&mut self, blend: BlendMode) { - let ret = - unsafe { sys::render::SDL_SetTextureBlendMode(self.raw, blend as u32) }; + let ret = unsafe { sys::render::SDL_SetTextureBlendMode(self.raw, blend as u32) }; if !ret { panic!("Error setting blend: {}", get_error()) diff --git a/src/sdl3/sdl.rs b/src/sdl3/sdl.rs index 97c88d31ba..de72d324bf 100644 --- a/src/sdl3/sdl.rs +++ b/src/sdl3/sdl.rs @@ -240,7 +240,7 @@ macro_rules! subsystem { result = sys::init::SDL_InitSubSystem($flag); } - if !result { + if !result { $counter.store(0, Ordering::Relaxed); return Err(get_error()); } @@ -307,38 +307,13 @@ impl Drop for SubsystemDrop { subsystem!(AudioSubsystem, SDL_INIT_AUDIO, AUDIO_COUNT, nosync); subsystem!(VideoSubsystem, SDL_INIT_VIDEO, VIDEO_COUNT, nosync); -subsystem!( - JoystickSubsystem, - SDL_INIT_JOYSTICK, - JOYSTICK_COUNT, - nosync -); -subsystem!( - HapticSubsystem, - SDL_INIT_HAPTIC, - HAPTIC_COUNT, - nosync -); -subsystem!( - GamepadSubsystem, - SDL_INIT_GAMEPAD, - GAMEPAD_COUNT, - nosync -); +subsystem!(JoystickSubsystem, SDL_INIT_JOYSTICK, JOYSTICK_COUNT, nosync); +subsystem!(HapticSubsystem, SDL_INIT_HAPTIC, HAPTIC_COUNT, nosync); +subsystem!(GamepadSubsystem, SDL_INIT_GAMEPAD, GAMEPAD_COUNT, nosync); // The event queue can be read from other threads. subsystem!(EventSubsystem, SDL_INIT_EVENTS, EVENT_COUNT, sync); -subsystem!( - SensorSubsystem, - SDL_INIT_SENSOR, - SENSOR_COUNT, - nosync -); -subsystem!( - CameraSubsystem, - SDL_INIT_CAMERA, - CAMERA_COUNT, - nosync -); +subsystem!(SensorSubsystem, SDL_INIT_SENSOR, SENSOR_COUNT, nosync); +subsystem!(CameraSubsystem, SDL_INIT_CAMERA, CAMERA_COUNT, nosync); static IS_EVENT_PUMP_ALIVE: AtomicBool = AtomicBool::new(false); diff --git a/src/sdl3/sensor.rs b/src/sdl3/sensor.rs index 02fa56048f..77f13250bb 100644 --- a/src/sdl3/sensor.rs +++ b/src/sdl3/sensor.rs @@ -18,7 +18,6 @@ /// - -z ... +z is roll from right to left use crate::sys; - use crate::common::IntegerOrSdlError; use crate::get_error; use crate::SensorSubsystem; diff --git a/src/sdl3/surface.rs b/src/sdl3/surface.rs index 1893b7a529..9c0e763557 100644 --- a/src/sdl3/surface.rs +++ b/src/sdl3/surface.rs @@ -5,6 +5,7 @@ use std::path::Path; use std::sync::Arc; use crate::get_error; +use crate::iostream::IOStream; use crate::pixels; use crate::rect::Rect; use crate::render::{BlendMode, Canvas}; @@ -16,7 +17,6 @@ use std::mem::transmute; use std::ptr; use sys::blendmode::SDL_BLENDMODE_NONE; use sys::surface::{SDL_ScaleMode, SDL_MUSTLOCK, SDL_SCALEMODE_LINEAR}; -use crate::iostream::IOStream; /// Holds a `SDL_Surface` /// @@ -58,7 +58,6 @@ pub struct SurfaceRef { _raw: (), } - impl AsRef for SurfaceRef { fn as_ref(&self) -> &SurfaceRef { self @@ -548,7 +547,7 @@ impl SurfaceRef { unsafe { let rect = rect.into(); let rect_ptr = mem::transmute(rect.as_ref()); // TODO find a better way to transform - // Option<&...> into a *const _ + // Option<&...> into a *const _ let format = self.pixel_format(); let result = sys::surface::SDL_FillSurfaceRect(self.raw(), rect_ptr, color.to_u32(&format)); @@ -734,12 +733,8 @@ impl SurfaceRef { // The rectangles don't change, but the function requires mutable pointers. let src_rect_ptr = src_rect.as_ref().map(|r| r.raw()).unwrap_or(ptr::null()) as *mut _; let dst_rect_ptr = dst_rect.as_ref().map(|r| r.raw()).unwrap_or(ptr::null()) as *mut _; - if sys::surface::SDL_BlitSurfaceUnchecked( - self.raw(), - src_rect_ptr, - dst.raw(), - dst_rect_ptr, - ) { + if sys::surface::SDL_BlitSurfaceUnchecked(self.raw(), src_rect_ptr, dst.raw(), dst_rect_ptr) + { Ok(()) } else { Err(get_error()) @@ -806,7 +801,7 @@ impl SurfaceRef { { let src_rect = src_rect.into(); let dst_rect = dst_rect.into(); - + let src_rect_ptr = src_rect.as_ref().map(|r| r.raw()).unwrap_or(ptr::null()); // Copy the rect here to make a mutable copy without requiring diff --git a/src/sdl3/url.rs b/src/sdl3/url.rs index e890c637ba..399c4194cc 100644 --- a/src/sdl3/url.rs +++ b/src/sdl3/url.rs @@ -6,7 +6,6 @@ use std::ffi::{CString, NulError}; use std::fmt; use sys::misc::SDL_OpenURL; - #[derive(Debug, Clone)] pub enum OpenUrlError { InvalidUrl(NulError), diff --git a/src/sdl3/video.rs b/src/sdl3/video.rs index a6c7ee427b..d3b4b18e19 100644 --- a/src/sdl3/video.rs +++ b/src/sdl3/video.rs @@ -515,7 +515,9 @@ pub struct GLContext { impl Drop for GLContext { #[doc(alias = "SDL_GL_DeleteContext")] fn drop(&mut self) { - unsafe { sys::video::SDL_GL_DestroyContext(self.raw); } + unsafe { + sys::video::SDL_GL_DestroyContext(self.raw); + } } } diff --git a/tests/raw_window_handle.rs b/tests/raw_window_handle.rs index 9b0998d54f..2bbb360958 100644 --- a/tests/raw_window_handle.rs +++ b/tests/raw_window_handle.rs @@ -3,8 +3,8 @@ mod raw_window_handle_test { extern crate raw_window_handle; extern crate sdl3; + use self::raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle}; use self::sdl3::video::Window; - use self::raw_window_handle::{HasWindowHandle, HasDisplayHandle, RawWindowHandle}; #[cfg(target_os = "windows")] #[test] @@ -21,10 +21,7 @@ mod raw_window_handle_test { }; let raw_handle = match window_handle.as_raw() { RawWindowHandle::Win32(v) => v, - x => panic!( - "Received wrong RawWindowHandle type for Windows: {:?}", - x - ), + x => panic!("Received wrong RawWindowHandle type for Windows: {:?}", x), }; assert_ne!(raw_handle.hwnd.get(), 0); println!("Successfully received Windows RawWindowHandle!"); @@ -36,11 +33,8 @@ mod raw_window_handle_test { ), }; match display_handle.as_raw() { - RawDisplayHandle::Windows(_) => {}, - x => panic!( - "Received wrong RawDisplayHandle type for Windows: {:?}", - x - ), + RawDisplayHandle::Windows(_) => {} + x => panic!("Received wrong RawDisplayHandle type for Windows: {:?}", x), } println!("Successfully received Windows RawDisplayHandle!"); }