From 90a25ea988fe79080584f89bb6478e0206345d4a Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Wed, 2 Sep 2020 16:23:03 -0500 Subject: [PATCH] cargo fmt --- examples/open_window.rs | 30 +++++++++++++-------------- src/lib.rs | 2 +- src/macos/window.rs | 18 +++++++---------- src/message.rs | 8 ++++---- src/win/window.rs | 15 ++++++-------- src/x11/mod.rs | 2 +- src/x11/opengl_util.rs | 15 ++++++-------- src/x11/window.rs | 45 ++++++++++++++++++----------------------- 8 files changed, 59 insertions(+), 76 deletions(-) diff --git a/examples/open_window.rs b/examples/open_window.rs index ad0f699..84f57e4 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -13,52 +13,50 @@ fn main() { baseview::Window::open(window_open_options, my_program); } -struct MyProgram { - -} +struct MyProgram {} impl baseview::Receiver for MyProgram { fn on_message(&mut self, message: Message) { match message { Message::CursorMotion(x, y) => { println!("Cursor moved, x: {}, y: {}", x, y); - }, + } Message::MouseDown(button_id) => { println!("Mouse down, button id: {:?}", button_id); - }, + } Message::MouseUp(button_id) => { println!("Mouse up, button id: {:?}", button_id); - }, + } Message::MouseScroll(mouse_scroll) => { println!("Mouse scroll, {:?}", mouse_scroll); - }, + } Message::MouseClick(mouse_click) => { println!("Mouse click, {:?}", mouse_click); } Message::KeyDown(keycode) => { println!("Key down, keycode: {}", keycode); - }, + } Message::KeyUp(keycode) => { println!("Key up, keycode: {}", keycode); - }, + } Message::CharacterInput(char_code) => { println!("Character input, char_code: {}", char_code); - }, + } Message::WindowResized(window_info) => { println!("Window resized, {:?}", window_info); - }, + } Message::WindowFocus => { println!("Window focused"); - }, + } Message::WindowUnfocus => { println!("Window unfocused"); - }, + } Message::Opened(window_info) => { println!("Window opened, {:?}", window_info); - }, + } Message::WillClose => { println!("Window will close"); - }, + } } } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 510896d..8f1fd3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,4 +35,4 @@ pub struct WindowOpenOptions<'a> { pub trait Receiver { fn on_message(&mut self, message: Message); -} \ No newline at end of file +} diff --git a/src/macos/window.rs b/src/macos/window.rs index 214a5a0..20def2f 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -6,7 +6,7 @@ use cocoa::appkit::{ use cocoa::base::{nil, NO}; use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString}; -use crate::{WindowOpenOptions, Message, Receiver, MouseButtonID, MouseScroll}; +use crate::{Message, MouseButtonID, MouseScroll, Receiver, WindowOpenOptions}; pub struct Window { receiver: R, @@ -44,17 +44,13 @@ impl Window { current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); app.run(); - receiver.on_message(Message::Opened( - crate::message::WindowInfo { - width: options.width as u32, - height: options.height as u32, - dpi: None, - } - )); + receiver.on_message(Message::Opened(crate::message::WindowInfo { + width: options.width as u32, + height: options.height as u32, + dpi: None, + })); - Window { - receiver, - } + Window { receiver } } } } diff --git a/src/message.rs b/src/message.rs index 93561a6..0d660db 100644 --- a/src/message.rs +++ b/src/message.rs @@ -43,12 +43,12 @@ pub enum Message { MouseUp(MouseButtonID), MouseScroll(MouseScroll), MouseClick(MouseClick), - KeyDown(u8), // keycode - KeyUp(u8), // keycode - CharacterInput(u32), // character code + KeyDown(u8), // keycode + KeyUp(u8), // keycode + CharacterInput(u32), // character code WindowResized(WindowInfo), // new (width, height) WindowFocus, WindowUnfocus, Opened(WindowInfo), WillClose, -} \ No newline at end of file +} diff --git a/src/win/window.rs b/src/win/window.rs index 102c1b6..529259c 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -25,7 +25,7 @@ use self::winapi::um::winuser::{ use self::winapi::ctypes::c_void; use crate::Parent::WithParent; use crate::{handle_message, WindowOpenOptions}; -use crate::{Message, Receiver, MouseButtonID, MouseScroll}; +use crate::{Message, MouseButtonID, MouseScroll, Receiver}; use std::sync::{Arc, Mutex}; unsafe fn message_box(title: &str, msg: &str) { @@ -241,13 +241,13 @@ impl Window { SetTimer(hwnd, 4242, 13, None); - window.receiver.on_message(Message::Opened( - crate::message::WindowInfo { + window + .receiver + .on_message(Message::Opened(crate::message::WindowInfo { width: options.width as u32, height: options.height as u32, dpi: window.scaling, - } - )); + })); // todo: decide what to do with the message pump if parent.is_null() { @@ -290,9 +290,6 @@ impl Window { self.r = r; self.g = g; - self.receiver.on_message(Message::CursorMotion( - x, - y, - )); + self.receiver.on_message(Message::CursorMotion(x, y)); } } diff --git a/src/x11/mod.rs b/src/x11/mod.rs index 02f8ba8..8006f4b 100644 --- a/src/x11/mod.rs +++ b/src/x11/mod.rs @@ -5,4 +5,4 @@ mod window; pub use window::*; #[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))] -mod opengl_util; \ No newline at end of file +mod opengl_util; diff --git a/src/x11/opengl_util.rs b/src/x11/opengl_util.rs index 3030dba..1ee7c3d 100644 --- a/src/x11/opengl_util.rs +++ b/src/x11/opengl_util.rs @@ -1,4 +1,4 @@ -use std::ffi::{CString, CStr}; +use std::ffi::{CStr, CString}; use std::os::raw::{c_int, c_void}; use std::ptr::null_mut; @@ -35,19 +35,16 @@ pub fn fb_config(xcb_connection: &XcbConnection) -> *mut glx::__GLXFBConfigRec { pub fn x_visual_info( xcb_connection: &XcbConnection, - fb_config: *mut glx::__GLXFBConfigRec + fb_config: *mut glx::__GLXFBConfigRec, ) -> *const xlib::XVisualInfo { // The GLX framebuffer config holds an XVisualInfo, which we'll need for other X operations. - - unsafe { glx::glXGetVisualFromFBConfig( - xcb_connection.conn.get_raw_dpy(), - fb_config - )} + + unsafe { glx::glXGetVisualFromFBConfig(xcb_connection.conn.get_raw_dpy(), fb_config) } } pub fn glx_context( xcb_connection: &XcbConnection, - fb_config: *mut glx::__GLXFBConfigRec + fb_config: *mut glx::__GLXFBConfigRec, ) -> *mut glx::__GLXcontextRec { // Load GLX extensions // We need at least `GLX_ARB_create_context` @@ -182,4 +179,4 @@ pub fn xcb_expose( glx::glXSwapBuffers(raw_display, window_id as xlib::XID); glx::glXMakeCurrent(raw_display, 0, null_mut()); } -} \ No newline at end of file +} diff --git a/src/x11/window.rs b/src/x11/window.rs index 349e9e0..2f53094 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -16,7 +16,7 @@ use ::x11::xlib; use super::opengl_util; use super::XcbConnection; -use crate::{Parent, WindowOpenOptions, Message, Receiver, MouseButtonID, MouseScroll}; +use crate::{Message, MouseButtonID, MouseScroll, Parent, Receiver, WindowOpenOptions}; pub struct Window { xcb_connection: XcbConnection, @@ -42,9 +42,8 @@ impl Window { #[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))] let fb_config = opengl_util::fb_config(&xcb_connection); #[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))] - let x_visual_info: *const xlib::XVisualInfo = { - opengl_util::x_visual_info(&xcb_connection, fb_config) - }; + let x_visual_info: *const xlib::XVisualInfo = + { opengl_util::x_visual_info(&xcb_connection, fb_config) }; // Load up DRI2 extensions. // See also: https://www.x.org/releases/X11R7.7/doc/dri2proto/dri2proto.txt @@ -176,13 +175,13 @@ impl Window { .or(x11_window.get_scaling_screen_dimensions()); println!("Scale factor: {:?}", x11_window.scaling); - x11_window.receiver.on_message(Message::Opened( - crate::message::WindowInfo { + x11_window + .receiver + .on_message(Message::Opened(crate::message::WindowInfo { width: options.width as u32, height: options.height as u32, dpi: x11_window.scaling, - } - )); + })); x11_window.handle_events(window_id); @@ -223,15 +222,15 @@ impl Window { xcb::EXPOSE => { #[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))] opengl_util::xcb_expose(window_id, raw_display, self.ctx); - }, + } xcb::MOTION_NOTIFY => { let event = unsafe { xcb::cast_event::(&event) }; let detail = event.detail(); if detail != 4 && detail != 5 { self.receiver.on_message(Message::CursorMotion( - event.event_x() as i32, - event.event_y() as i32, + event.event_x() as i32, + event.event_y() as i32, )); } } @@ -241,20 +240,16 @@ impl Window { match detail { 4 => { - self.receiver.on_message(Message::MouseScroll( - MouseScroll { - x_delta: 0.0, - y_delta: 1.0, - } - )); - }, + self.receiver.on_message(Message::MouseScroll(MouseScroll { + x_delta: 0.0, + y_delta: 1.0, + })); + } 5 => { - self.receiver.on_message(Message::MouseScroll( - MouseScroll { - x_delta: 0.0, - y_delta: -1.0, - } - )); + self.receiver.on_message(Message::MouseScroll(MouseScroll { + x_delta: 0.0, + y_delta: -1.0, + })); } detail => { let button_id = mouse_id(detail); @@ -380,4 +375,4 @@ fn mouse_id(id: u8) -> MouseButtonID { 7 => MouseButtonID::Forward, id => MouseButtonID::Other(id), } -} \ No newline at end of file +}