Format everything and add rustfmt to travis (#951)
* Format everything and add rustfmt to travis * Remove extern crate winit from examples and add force_multiline_blocks * Format the code properly * Fix inconsistent period in PULL_REQUEST_TEMPLATE.md * Only run rustfmt on nightly * Travis fixings
This commit is contained in:
parent
b1b5aefc4b
commit
e2c84725de
109 changed files with 4787 additions and 3679 deletions
|
|
@ -10,8 +10,10 @@ use cocoa::{
|
|||
};
|
||||
use dispatch::ffi::{dispatch_async_f, dispatch_get_main_queue, dispatch_sync_f};
|
||||
|
||||
use crate::dpi::LogicalSize;
|
||||
use crate::platform_impl::platform::{ffi, util::IdRef, window::SharedState};
|
||||
use crate::{
|
||||
dpi::LogicalSize,
|
||||
platform_impl::platform::{ffi, util::IdRef, window::SharedState},
|
||||
};
|
||||
|
||||
unsafe fn set_style_mask(ns_window: id, ns_view: id, mask: NSWindowStyleMask) {
|
||||
ns_window.setStyleMask_(mask);
|
||||
|
|
@ -26,15 +28,15 @@ struct SetStyleMaskData {
|
|||
mask: NSWindowStyleMask,
|
||||
}
|
||||
impl SetStyleMaskData {
|
||||
fn new_ptr(
|
||||
ns_window: id,
|
||||
ns_view: id,
|
||||
mask: NSWindowStyleMask,
|
||||
) -> *mut Self {
|
||||
Box::into_raw(Box::new(SetStyleMaskData { ns_window, ns_view, mask }))
|
||||
fn new_ptr(ns_window: id, ns_view: id, mask: NSWindowStyleMask) -> *mut Self {
|
||||
Box::into_raw(Box::new(SetStyleMaskData {
|
||||
ns_window,
|
||||
ns_view,
|
||||
mask,
|
||||
}))
|
||||
}
|
||||
}
|
||||
extern fn set_style_mask_callback(context: *mut c_void) {
|
||||
extern "C" fn set_style_mask_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut SetStyleMaskData;
|
||||
{
|
||||
|
|
@ -70,14 +72,11 @@ struct SetContentSizeData {
|
|||
size: LogicalSize,
|
||||
}
|
||||
impl SetContentSizeData {
|
||||
fn new_ptr(
|
||||
ns_window: id,
|
||||
size: LogicalSize,
|
||||
) -> *mut Self {
|
||||
fn new_ptr(ns_window: id, size: LogicalSize) -> *mut Self {
|
||||
Box::into_raw(Box::new(SetContentSizeData { ns_window, size }))
|
||||
}
|
||||
}
|
||||
extern fn set_content_size_callback(context: *mut c_void) {
|
||||
extern "C" fn set_content_size_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut SetContentSizeData;
|
||||
{
|
||||
|
|
@ -109,14 +108,11 @@ struct SetFrameTopLeftPointData {
|
|||
point: NSPoint,
|
||||
}
|
||||
impl SetFrameTopLeftPointData {
|
||||
fn new_ptr(
|
||||
ns_window: id,
|
||||
point: NSPoint,
|
||||
) -> *mut Self {
|
||||
fn new_ptr(ns_window: id, point: NSPoint) -> *mut Self {
|
||||
Box::into_raw(Box::new(SetFrameTopLeftPointData { ns_window, point }))
|
||||
}
|
||||
}
|
||||
extern fn set_frame_top_left_point_callback(context: *mut c_void) {
|
||||
extern "C" fn set_frame_top_left_point_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut SetFrameTopLeftPointData;
|
||||
{
|
||||
|
|
@ -142,14 +138,11 @@ struct SetLevelData {
|
|||
level: ffi::NSWindowLevel,
|
||||
}
|
||||
impl SetLevelData {
|
||||
fn new_ptr(
|
||||
ns_window: id,
|
||||
level: ffi::NSWindowLevel,
|
||||
) -> *mut Self {
|
||||
fn new_ptr(ns_window: id, level: ffi::NSWindowLevel) -> *mut Self {
|
||||
Box::into_raw(Box::new(SetLevelData { ns_window, level }))
|
||||
}
|
||||
}
|
||||
extern fn set_level_callback(context: *mut c_void) {
|
||||
extern "C" fn set_level_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut SetLevelData;
|
||||
{
|
||||
|
|
@ -190,7 +183,7 @@ impl ToggleFullScreenData {
|
|||
}))
|
||||
}
|
||||
}
|
||||
extern fn toggle_full_screen_callback(context: *mut c_void) {
|
||||
extern "C" fn toggle_full_screen_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut ToggleFullScreenData;
|
||||
{
|
||||
|
|
@ -227,12 +220,7 @@ pub unsafe fn toggle_full_screen_async(
|
|||
not_fullscreen: bool,
|
||||
shared_state: Weak<Mutex<SharedState>>,
|
||||
) {
|
||||
let context = ToggleFullScreenData::new_ptr(
|
||||
ns_window,
|
||||
ns_view,
|
||||
not_fullscreen,
|
||||
shared_state,
|
||||
);
|
||||
let context = ToggleFullScreenData::new_ptr(ns_window, ns_view, not_fullscreen, shared_state);
|
||||
dispatch_async_f(
|
||||
dispatch_get_main_queue(),
|
||||
context as *mut _,
|
||||
|
|
@ -325,7 +313,7 @@ impl OrderOutData {
|
|||
Box::into_raw(Box::new(OrderOutData { ns_window }))
|
||||
}
|
||||
}
|
||||
extern fn order_out_callback(context: *mut c_void) {
|
||||
extern "C" fn order_out_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut OrderOutData;
|
||||
{
|
||||
|
|
@ -354,7 +342,7 @@ impl MakeKeyAndOrderFrontData {
|
|||
Box::into_raw(Box::new(MakeKeyAndOrderFrontData { ns_window }))
|
||||
}
|
||||
}
|
||||
extern fn make_key_and_order_front_callback(context: *mut c_void) {
|
||||
extern "C" fn make_key_and_order_front_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut MakeKeyAndOrderFrontData;
|
||||
{
|
||||
|
|
@ -415,7 +403,7 @@ impl CloseData {
|
|||
Box::into_raw(Box::new(CloseData { ns_window }))
|
||||
}
|
||||
}
|
||||
extern fn close_callback(context: *mut c_void) {
|
||||
extern "C" fn close_callback(context: *mut c_void) {
|
||||
unsafe {
|
||||
let context_ptr = context as *mut CloseData;
|
||||
{
|
||||
|
|
@ -431,9 +419,5 @@ extern fn close_callback(context: *mut c_void) {
|
|||
// thread. Though, it's a good idea to look into that more...
|
||||
pub unsafe fn close_async(ns_window: id) {
|
||||
let context = CloseData::new_ptr(ns_window);
|
||||
dispatch_async_f(
|
||||
dispatch_get_main_queue(),
|
||||
context as *mut _,
|
||||
close_callback,
|
||||
);
|
||||
dispatch_async_f(dispatch_get_main_queue(), context as *mut _, close_callback);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use cocoa::{
|
||||
appkit::NSImage, base::{id, nil},
|
||||
appkit::NSImage,
|
||||
base::{id, nil},
|
||||
foundation::{NSDictionary, NSPoint, NSString},
|
||||
};
|
||||
use objc::runtime::Sel;
|
||||
|
|
@ -22,7 +23,9 @@ impl From<CursorIcon> for Cursor {
|
|||
CursorIcon::VerticalText => Cursor::Native("IBeamCursorForVerticalLayout"),
|
||||
CursorIcon::Copy => Cursor::Native("dragCopyCursor"),
|
||||
CursorIcon::Alias => Cursor::Native("dragLinkCursor"),
|
||||
CursorIcon::NotAllowed | CursorIcon::NoDrop => Cursor::Native("operationNotAllowedCursor"),
|
||||
CursorIcon::NotAllowed | CursorIcon::NoDrop => {
|
||||
Cursor::Native("operationNotAllowedCursor")
|
||||
},
|
||||
CursorIcon::ContextMenu => Cursor::Native("contextualMenuCursor"),
|
||||
CursorIcon::Crosshair => Cursor::Native("crosshairCursor"),
|
||||
CursorIcon::EResize => Cursor::Native("resizeRightCursor"),
|
||||
|
|
@ -52,7 +55,9 @@ impl From<CursorIcon> for Cursor {
|
|||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=522349
|
||||
// This is the wrong semantics for `Wait`, but it's the same as
|
||||
// what's used in Safari and Chrome.
|
||||
CursorIcon::Wait | CursorIcon::Progress => Cursor::Undocumented("busyButClickableCursor"),
|
||||
CursorIcon::Wait | CursorIcon::Progress => {
|
||||
Cursor::Undocumented("busyButClickableCursor")
|
||||
},
|
||||
|
||||
// For the rest, we can just snatch the cursors from WebKit...
|
||||
// They fit the style of the native cursors, and will seem
|
||||
|
|
@ -75,18 +80,18 @@ impl Cursor {
|
|||
match self {
|
||||
Cursor::Native(cursor_name) => {
|
||||
let sel = Sel::register(cursor_name);
|
||||
msg_send![class!(NSCursor), performSelector:sel]
|
||||
msg_send![class!(NSCursor), performSelector: sel]
|
||||
},
|
||||
Cursor::Undocumented(cursor_name) => {
|
||||
let class = class!(NSCursor);
|
||||
let sel = Sel::register(cursor_name);
|
||||
let sel = if msg_send![class, respondsToSelector:sel] {
|
||||
let sel = if msg_send![class, respondsToSelector: sel] {
|
||||
sel
|
||||
} else {
|
||||
warn!("Cursor `{}` appears to be invalid", cursor_name);
|
||||
sel!(arrowCursor)
|
||||
};
|
||||
msg_send![class, performSelector:sel]
|
||||
msg_send![class, performSelector: sel]
|
||||
},
|
||||
Cursor::WebKit(cursor_name) => load_webkit_cursor(cursor_name),
|
||||
}
|
||||
|
|
@ -104,27 +109,15 @@ pub unsafe fn load_webkit_cursor(cursor_name: &str) -> id {
|
|||
let key_x = NSString::alloc(nil).init_str("hotx");
|
||||
let key_y = NSString::alloc(nil).init_str("hoty");
|
||||
|
||||
let cursor_path: id = msg_send![cursor_root,
|
||||
stringByAppendingPathComponent:cursor_name
|
||||
];
|
||||
let pdf_path: id = msg_send![cursor_path,
|
||||
stringByAppendingPathComponent:cursor_pdf
|
||||
];
|
||||
let info_path: id = msg_send![cursor_path,
|
||||
stringByAppendingPathComponent:cursor_plist
|
||||
];
|
||||
let cursor_path: id = msg_send![cursor_root, stringByAppendingPathComponent: cursor_name];
|
||||
let pdf_path: id = msg_send![cursor_path, stringByAppendingPathComponent: cursor_pdf];
|
||||
let info_path: id = msg_send![cursor_path, stringByAppendingPathComponent: cursor_plist];
|
||||
|
||||
let image = NSImage::alloc(nil).initByReferencingFile_(pdf_path);
|
||||
let info = NSDictionary::dictionaryWithContentsOfFile_(
|
||||
nil,
|
||||
info_path,
|
||||
);
|
||||
let info = NSDictionary::dictionaryWithContentsOfFile_(nil, info_path);
|
||||
let x = info.valueForKey_(key_x);
|
||||
let y = info.valueForKey_(key_y);
|
||||
let point = NSPoint::new(
|
||||
msg_send![x, doubleValue],
|
||||
msg_send![y, doubleValue],
|
||||
);
|
||||
let point = NSPoint::new(msg_send![x, doubleValue], msg_send![y, doubleValue]);
|
||||
let cursor: id = msg_send![class!(NSCursor), alloc];
|
||||
msg_send![cursor,
|
||||
initWithImage:image
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
mod r#async;
|
||||
mod cursor;
|
||||
|
||||
pub use self::{r#async::*, cursor::*};
|
||||
pub use self::{cursor::*, r#async::*};
|
||||
|
||||
use std::ops::Deref;
|
||||
use std::ops::BitAnd;
|
||||
use std::ops::{BitAnd, Deref};
|
||||
|
||||
use cocoa::{
|
||||
appkit::{NSApp, NSWindowStyleMask},
|
||||
|
|
@ -12,7 +11,7 @@ use cocoa::{
|
|||
foundation::{NSAutoreleasePool, NSRect, NSUInteger},
|
||||
};
|
||||
use core_graphics::display::CGDisplay;
|
||||
use objc::runtime::{BOOL, Class, Object, Sel, YES};
|
||||
use objc::runtime::{Class, Object, Sel, BOOL, YES};
|
||||
|
||||
use crate::platform_impl::platform::ffi;
|
||||
|
||||
|
|
@ -21,8 +20,8 @@ use crate::platform_impl::platform::ffi;
|
|||
pub enum Never {}
|
||||
|
||||
pub fn has_flag<T>(bitset: T, flag: T) -> bool
|
||||
where T:
|
||||
Copy + PartialEq + BitAnd<T, Output = T>
|
||||
where
|
||||
T: Copy + PartialEq + BitAnd<T, Output = T>,
|
||||
{
|
||||
bitset & flag == flag
|
||||
}
|
||||
|
|
@ -48,7 +47,11 @@ impl IdRef {
|
|||
}
|
||||
|
||||
pub fn non_nil(self) -> Option<IdRef> {
|
||||
if self.0 == nil { None } else { Some(self) }
|
||||
if self.0 == nil {
|
||||
None
|
||||
} else {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,16 +97,16 @@ pub unsafe fn superclass<'a>(this: &'a Object) -> &'a Class {
|
|||
|
||||
pub unsafe fn create_input_context(view: id) -> IdRef {
|
||||
let input_context: id = msg_send![class!(NSTextInputContext), alloc];
|
||||
let input_context: id = msg_send![input_context, initWithClient:view];
|
||||
let input_context: id = msg_send![input_context, initWithClient: view];
|
||||
IdRef::new(input_context)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub unsafe fn open_emoji_picker() {
|
||||
let () = msg_send![NSApp(), orderFrontCharacterPalette:nil];
|
||||
let () = msg_send![NSApp(), orderFrontCharacterPalette: nil];
|
||||
}
|
||||
|
||||
pub extern fn yes(_: &Object, _: Sel) -> BOOL {
|
||||
pub extern "C" fn yes(_: &Object, _: Sel) -> BOOL {
|
||||
YES
|
||||
}
|
||||
|
||||
|
|
@ -120,4 +123,3 @@ pub unsafe fn toggle_style_mask(window: id, view: id, mask: NSWindowStyleMask, o
|
|||
// If we don't do this, key handling will break. Therefore, never call `setStyleMask` directly!
|
||||
window.makeFirstResponder_(view);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue