1
0
Fork 0

cargo fmt

This commit is contained in:
Billy Messenger 2020-09-02 16:23:03 -05:00
parent 9234f050c0
commit 90a25ea988
8 changed files with 59 additions and 76 deletions

View file

@ -13,52 +13,50 @@ fn main() {
baseview::Window::open(window_open_options, my_program); baseview::Window::open(window_open_options, my_program);
} }
struct MyProgram { struct MyProgram {}
}
impl baseview::Receiver for MyProgram { impl baseview::Receiver for MyProgram {
fn on_message(&mut self, message: Message) { fn on_message(&mut self, message: Message) {
match message { match message {
Message::CursorMotion(x, y) => { Message::CursorMotion(x, y) => {
println!("Cursor moved, x: {}, y: {}", x, y); println!("Cursor moved, x: {}, y: {}", x, y);
}, }
Message::MouseDown(button_id) => { Message::MouseDown(button_id) => {
println!("Mouse down, button id: {:?}", button_id); println!("Mouse down, button id: {:?}", button_id);
}, }
Message::MouseUp(button_id) => { Message::MouseUp(button_id) => {
println!("Mouse up, button id: {:?}", button_id); println!("Mouse up, button id: {:?}", button_id);
}, }
Message::MouseScroll(mouse_scroll) => { Message::MouseScroll(mouse_scroll) => {
println!("Mouse scroll, {:?}", mouse_scroll); println!("Mouse scroll, {:?}", mouse_scroll);
}, }
Message::MouseClick(mouse_click) => { Message::MouseClick(mouse_click) => {
println!("Mouse click, {:?}", mouse_click); println!("Mouse click, {:?}", mouse_click);
} }
Message::KeyDown(keycode) => { Message::KeyDown(keycode) => {
println!("Key down, keycode: {}", keycode); println!("Key down, keycode: {}", keycode);
}, }
Message::KeyUp(keycode) => { Message::KeyUp(keycode) => {
println!("Key up, keycode: {}", keycode); println!("Key up, keycode: {}", keycode);
}, }
Message::CharacterInput(char_code) => { Message::CharacterInput(char_code) => {
println!("Character input, char_code: {}", char_code); println!("Character input, char_code: {}", char_code);
}, }
Message::WindowResized(window_info) => { Message::WindowResized(window_info) => {
println!("Window resized, {:?}", window_info); println!("Window resized, {:?}", window_info);
}, }
Message::WindowFocus => { Message::WindowFocus => {
println!("Window focused"); println!("Window focused");
}, }
Message::WindowUnfocus => { Message::WindowUnfocus => {
println!("Window unfocused"); println!("Window unfocused");
}, }
Message::Opened(window_info) => { Message::Opened(window_info) => {
println!("Window opened, {:?}", window_info); println!("Window opened, {:?}", window_info);
}, }
Message::WillClose => { Message::WillClose => {
println!("Window will close"); println!("Window will close");
}, }
} }
} }
} }

View file

@ -6,7 +6,7 @@ use cocoa::appkit::{
use cocoa::base::{nil, NO}; use cocoa::base::{nil, NO};
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString}; 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<R: Receiver> { pub struct Window<R: Receiver> {
receiver: R, receiver: R,
@ -44,17 +44,13 @@ impl<R: Receiver> Window<R> {
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
app.run(); app.run();
receiver.on_message(Message::Opened( receiver.on_message(Message::Opened(crate::message::WindowInfo {
crate::message::WindowInfo {
width: options.width as u32, width: options.width as u32,
height: options.height as u32, height: options.height as u32,
dpi: None, dpi: None,
} }));
));
Window { Window { receiver }
receiver,
}
} }
} }
} }

View file

@ -25,7 +25,7 @@ use self::winapi::um::winuser::{
use self::winapi::ctypes::c_void; use self::winapi::ctypes::c_void;
use crate::Parent::WithParent; use crate::Parent::WithParent;
use crate::{handle_message, WindowOpenOptions}; use crate::{handle_message, WindowOpenOptions};
use crate::{Message, Receiver, MouseButtonID, MouseScroll}; use crate::{Message, MouseButtonID, MouseScroll, Receiver};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
unsafe fn message_box(title: &str, msg: &str) { unsafe fn message_box(title: &str, msg: &str) {
@ -241,13 +241,13 @@ impl<R: Receiver> Window<R> {
SetTimer(hwnd, 4242, 13, None); SetTimer(hwnd, 4242, 13, None);
window.receiver.on_message(Message::Opened( window
crate::message::WindowInfo { .receiver
.on_message(Message::Opened(crate::message::WindowInfo {
width: options.width as u32, width: options.width as u32,
height: options.height as u32, height: options.height as u32,
dpi: window.scaling, dpi: window.scaling,
} }));
));
// todo: decide what to do with the message pump // todo: decide what to do with the message pump
if parent.is_null() { if parent.is_null() {
@ -290,9 +290,6 @@ impl<R: Receiver> Window<R> {
self.r = r; self.r = r;
self.g = g; self.g = g;
self.receiver.on_message(Message::CursorMotion( self.receiver.on_message(Message::CursorMotion(x, y));
x,
y,
));
} }
} }

View file

@ -1,4 +1,4 @@
use std::ffi::{CString, CStr}; use std::ffi::{CStr, CString};
use std::os::raw::{c_int, c_void}; use std::os::raw::{c_int, c_void};
use std::ptr::null_mut; use std::ptr::null_mut;
@ -35,19 +35,16 @@ pub fn fb_config(xcb_connection: &XcbConnection) -> *mut glx::__GLXFBConfigRec {
pub fn x_visual_info( pub fn x_visual_info(
xcb_connection: &XcbConnection, xcb_connection: &XcbConnection,
fb_config: *mut glx::__GLXFBConfigRec fb_config: *mut glx::__GLXFBConfigRec,
) -> *const xlib::XVisualInfo { ) -> *const xlib::XVisualInfo {
// The GLX framebuffer config holds an XVisualInfo, which we'll need for other X operations. // The GLX framebuffer config holds an XVisualInfo, which we'll need for other X operations.
unsafe { glx::glXGetVisualFromFBConfig( unsafe { glx::glXGetVisualFromFBConfig(xcb_connection.conn.get_raw_dpy(), fb_config) }
xcb_connection.conn.get_raw_dpy(),
fb_config
)}
} }
pub fn glx_context( pub fn glx_context(
xcb_connection: &XcbConnection, xcb_connection: &XcbConnection,
fb_config: *mut glx::__GLXFBConfigRec fb_config: *mut glx::__GLXFBConfigRec,
) -> *mut glx::__GLXcontextRec { ) -> *mut glx::__GLXcontextRec {
// Load GLX extensions // Load GLX extensions
// We need at least `GLX_ARB_create_context` // We need at least `GLX_ARB_create_context`

View file

@ -16,7 +16,7 @@ use ::x11::xlib;
use super::opengl_util; use super::opengl_util;
use super::XcbConnection; use super::XcbConnection;
use crate::{Parent, WindowOpenOptions, Message, Receiver, MouseButtonID, MouseScroll}; use crate::{Message, MouseButtonID, MouseScroll, Parent, Receiver, WindowOpenOptions};
pub struct Window<R: Receiver> { pub struct Window<R: Receiver> {
xcb_connection: XcbConnection, xcb_connection: XcbConnection,
@ -42,9 +42,8 @@ impl<R: Receiver> Window<R> {
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))] #[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
let fb_config = opengl_util::fb_config(&xcb_connection); let fb_config = opengl_util::fb_config(&xcb_connection);
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))] #[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
let x_visual_info: *const xlib::XVisualInfo = { let x_visual_info: *const xlib::XVisualInfo =
opengl_util::x_visual_info(&xcb_connection, fb_config) { opengl_util::x_visual_info(&xcb_connection, fb_config) };
};
// Load up DRI2 extensions. // Load up DRI2 extensions.
// See also: https://www.x.org/releases/X11R7.7/doc/dri2proto/dri2proto.txt // See also: https://www.x.org/releases/X11R7.7/doc/dri2proto/dri2proto.txt
@ -176,13 +175,13 @@ impl<R: Receiver> Window<R> {
.or(x11_window.get_scaling_screen_dimensions()); .or(x11_window.get_scaling_screen_dimensions());
println!("Scale factor: {:?}", x11_window.scaling); println!("Scale factor: {:?}", x11_window.scaling);
x11_window.receiver.on_message(Message::Opened( x11_window
crate::message::WindowInfo { .receiver
.on_message(Message::Opened(crate::message::WindowInfo {
width: options.width as u32, width: options.width as u32,
height: options.height as u32, height: options.height as u32,
dpi: x11_window.scaling, dpi: x11_window.scaling,
} }));
));
x11_window.handle_events(window_id); x11_window.handle_events(window_id);
@ -223,7 +222,7 @@ impl<R: Receiver> Window<R> {
xcb::EXPOSE => { xcb::EXPOSE => {
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))] #[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
opengl_util::xcb_expose(window_id, raw_display, self.ctx); opengl_util::xcb_expose(window_id, raw_display, self.ctx);
}, }
xcb::MOTION_NOTIFY => { xcb::MOTION_NOTIFY => {
let event = unsafe { xcb::cast_event::<xcb::MotionNotifyEvent>(&event) }; let event = unsafe { xcb::cast_event::<xcb::MotionNotifyEvent>(&event) };
let detail = event.detail(); let detail = event.detail();
@ -241,20 +240,16 @@ impl<R: Receiver> Window<R> {
match detail { match detail {
4 => { 4 => {
self.receiver.on_message(Message::MouseScroll( self.receiver.on_message(Message::MouseScroll(MouseScroll {
MouseScroll {
x_delta: 0.0, x_delta: 0.0,
y_delta: 1.0, y_delta: 1.0,
}));
} }
));
},
5 => { 5 => {
self.receiver.on_message(Message::MouseScroll( self.receiver.on_message(Message::MouseScroll(MouseScroll {
MouseScroll {
x_delta: 0.0, x_delta: 0.0,
y_delta: -1.0, y_delta: -1.0,
} }));
));
} }
detail => { detail => {
let button_id = mouse_id(detail); let button_id = mouse_id(detail);