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);
}
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");
},
}
}
}
}

View file

@ -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<R: Receiver> {
receiver: R,
@ -44,17 +44,13 @@ impl<R: Receiver> Window<R> {
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
app.run();
receiver.on_message(Message::Opened(
crate::message::WindowInfo {
receiver.on_message(Message::Opened(crate::message::WindowInfo {
width: options.width as u32,
height: options.height as u32,
dpi: None,
}
));
}));
Window {
receiver,
}
Window { receiver }
}
}
}

View file

@ -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<R: Receiver> Window<R> {
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<R: Receiver> Window<R> {
self.r = r;
self.g = g;
self.receiver.on_message(Message::CursorMotion(
x,
y,
));
self.receiver.on_message(Message::CursorMotion(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::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`

View file

@ -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<R: Receiver> {
xcb_connection: XcbConnection,
@ -42,9 +42,8 @@ impl<R: Receiver> Window<R> {
#[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<R: Receiver> Window<R> {
.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,7 +222,7 @@ impl<R: Receiver> Window<R> {
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::<xcb::MotionNotifyEvent>(&event) };
let detail = event.detail();
@ -241,20 +240,16 @@ impl<R: Receiver> Window<R> {
match detail {
4 => {
self.receiver.on_message(Message::MouseScroll(
MouseScroll {
self.receiver.on_message(Message::MouseScroll(MouseScroll {
x_delta: 0.0,
y_delta: 1.0,
}));
}
));
},
5 => {
self.receiver.on_message(Message::MouseScroll(
MouseScroll {
self.receiver.on_message(Message::MouseScroll(MouseScroll {
x_delta: 0.0,
y_delta: -1.0,
}
));
}));
}
detail => {
let button_id = mouse_id(detail);