Updates for recent versions of Rust.
* Added lots of dyns * Removed unused whitespace. * Removed rust-toolchain because stable rust compiles the project. * Fixed Doc-tests with ignore keyword.
This commit is contained in:
parent
f15cf258af
commit
5695ec9b94
23 changed files with 170 additions and 171 deletions
|
|
@ -1,7 +1,7 @@
|
|||
//! A wrapper for `NSApplication` on macOS. If you opt in to the `cocoa` feature on
|
||||
//! Alchemy, this will loop system-level application events back to your `AppDelegate`.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use cocoa::base::{id, nil};
|
||||
use cocoa::appkit::{NSApplication, NSRunningApplication};
|
||||
|
|
@ -15,7 +15,7 @@ use alchemy_lifecycle::traits::AppDelegate;
|
|||
|
||||
static ALCHEMY_APP_PTR: &str = "alchemyParentAppPtr";
|
||||
|
||||
/// A wrapper for `NSApplication`. It holds (retains) pointers for the Objective-C runtime,
|
||||
/// A wrapper for `NSApplication`. It holds (retains) pointers for the Objective-C runtime,
|
||||
/// which is where our application instance lives. It also injects an `NSObject` subclass,
|
||||
/// which acts as the Delegate, looping back into our Alchemy shared application.
|
||||
pub struct App {
|
||||
|
|
@ -34,7 +34,7 @@ impl App {
|
|||
app.setActivationPolicy_(cocoa::appkit::NSApplicationActivationPolicyRegular);
|
||||
Id::from_ptr(app)
|
||||
};
|
||||
|
||||
|
||||
let delegate = unsafe {
|
||||
let delegate_class = register_app_delegate_class::<T>();
|
||||
let delegate: id = msg_send![delegate_class, new];
|
||||
|
|
@ -127,7 +127,7 @@ extern fn will_terminate<T: AppDelegate>(this: &Object, _: Sel, _: id) {
|
|||
/// pointers we need to have.
|
||||
fn register_app_delegate_class<T: AppDelegate>() -> *const Class {
|
||||
static mut DELEGATE_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSObject").unwrap();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! This wraps NTextField on macOS, and configures it to act like a label
|
||||
//! with standard behavior that most users would expect.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use objc_id::{Id, ShareId};
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
|
|
@ -19,7 +19,7 @@ use alchemy_lifecycle::traits::PlatformSpecificNodeType;
|
|||
|
||||
static ALCHEMY_DELEGATE: &str = "alchemyDelegate";
|
||||
|
||||
/// A wrapper for `NSText`. This holds retained pointers for the Objective-C
|
||||
/// A wrapper for `NSText`. This holds retained pointers for the Objective-C
|
||||
/// runtime - namely, the view itself, and associated things such as background
|
||||
/// colors and so forth.
|
||||
#[derive(Debug)]
|
||||
|
|
@ -83,7 +83,7 @@ impl Text {
|
|||
|
||||
self.background_color = appearance.background_color.into_nscolor();
|
||||
self.text_color = appearance.text_color.into_nscolor();
|
||||
|
||||
|
||||
msg_send![&*self.inner_mut, setFrame:rect];
|
||||
msg_send![&*self.inner_mut, setBackgroundColor:&*self.background_color];
|
||||
msg_send![&*self.inner_mut, setTextColor:&*self.text_color];
|
||||
|
|
@ -112,12 +112,12 @@ extern fn enforce_normalcy(_: &Object, _: Sel) -> BOOL {
|
|||
/// to store.
|
||||
fn register_class() -> *const Class {
|
||||
static mut VIEW_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSTextField").unwrap();
|
||||
let mut decl = ClassDecl::new("AlchemyTextField", superclass).unwrap();
|
||||
|
||||
|
||||
// Force NSText to render from the top-left, not bottom-left
|
||||
//decl.add_method(sel!(isFlipped), enforce_normalcy as extern fn(&Object, _) -> BOOL);
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ fn register_class() -> *const Class {
|
|||
// Note that NSText's don't really have a "delegate", I'm just using it here
|
||||
// for common terminology sake.
|
||||
decl.add_ivar::<usize>(ALCHEMY_DELEGATE);
|
||||
|
||||
|
||||
VIEW_CLASS = decl.register();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Implements a View Component struct. The most common
|
||||
//! basic building block of any app. Wraps NSView on macOS.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use objc_id::{Id, ShareId};
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
|
|
@ -20,7 +20,7 @@ use alchemy_lifecycle::traits::PlatformSpecificNodeType;
|
|||
static ALCHEMY_DELEGATE: &str = "alchemyDelegate";
|
||||
static BACKGROUND_COLOR: &str = "alchemyBackgroundColor";
|
||||
|
||||
/// A wrapper for `NSView`. This holds retained pointers for the Objective-C
|
||||
/// A wrapper for `NSView`. This holds retained pointers for the Objective-C
|
||||
/// runtime - namely, the view itself, and associated things such as background
|
||||
/// colors and so forth.
|
||||
#[derive(Debug)]
|
||||
|
|
@ -76,8 +76,8 @@ impl View {
|
|||
);
|
||||
|
||||
self.background_color = appearance.background_color.into_nscolor();
|
||||
self.inner_mut.set_ivar(BACKGROUND_COLOR, &*self.background_color);
|
||||
|
||||
self.inner_mut.set_ivar(BACKGROUND_COLOR, &*self.background_color);
|
||||
|
||||
msg_send![&*self.inner_mut, setFrame:rect];
|
||||
msg_send![&*self.inner_mut, setNeedsDisplay:YES];
|
||||
}
|
||||
|
|
@ -107,12 +107,12 @@ extern fn update_layer(this: &Object, _: Sel) {
|
|||
/// to store.
|
||||
fn register_class() -> *const Class {
|
||||
static mut VIEW_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSView").unwrap();
|
||||
let mut decl = ClassDecl::new("AlchemyView", superclass).unwrap();
|
||||
|
||||
|
||||
// Force NSView to render from the top-left, not bottom-left
|
||||
decl.add_method(sel!(isFlipped), enforce_normalcy as extern fn(&Object, _) -> BOOL);
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ fn register_class() -> *const Class {
|
|||
// for common terminology sake.
|
||||
decl.add_ivar::<usize>(ALCHEMY_DELEGATE);
|
||||
decl.add_ivar::<id>(BACKGROUND_COLOR);
|
||||
|
||||
|
||||
VIEW_CLASS = decl.register();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//! Cocoa and associated widgets. This also handles looping back
|
||||
//! lifecycle events, such as window resizing or close events.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use cocoa::base::{id, nil, YES, NO};
|
||||
use cocoa::appkit::{NSWindow, NSWindowStyleMask, NSBackingStoreType};
|
||||
|
|
@ -19,7 +19,7 @@ use alchemy_styles::Appearance;
|
|||
static APP_PTR: &str = "alchemyAppPtr";
|
||||
static WINDOW_MANAGER_ID: &str = "alchemyWindowManagerID";
|
||||
|
||||
/// A wrapper for `NSWindow`. Holds (retains) pointers for the Objective-C runtime
|
||||
/// A wrapper for `NSWindow`. Holds (retains) pointers for the Objective-C runtime
|
||||
/// where our `NSWindow` and associated delegate live.
|
||||
pub struct Window {
|
||||
pub inner: ShareId<Object>,
|
||||
|
|
@ -39,7 +39,7 @@ impl Window {
|
|||
|
||||
let inner = unsafe {
|
||||
let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
|
||||
dimensions,
|
||||
dimensions,
|
||||
style,
|
||||
NSBackingStoreType::NSBackingStoreBuffered,
|
||||
NO
|
||||
|
|
@ -52,14 +52,14 @@ impl Window {
|
|||
// to disable, like... this. If we don't set this, we'll segfault entirely because the
|
||||
// Objective-C runtime gets out of sync.
|
||||
msg_send![window, setReleasedWhenClosed:NO];
|
||||
|
||||
|
||||
//if let Some(view_ptr) = content_view.borrow_native_backing_node() {
|
||||
msg_send![window, setContentView:content_view];
|
||||
//}
|
||||
|
||||
ShareId::from_ptr(window)
|
||||
};
|
||||
|
||||
|
||||
let delegate = unsafe {
|
||||
let delegate_class = register_window_class::<T>();
|
||||
let delegate: id = msg_send![delegate_class, new];
|
||||
|
|
@ -128,7 +128,7 @@ impl Drop for Window {
|
|||
/// safer than sorry.
|
||||
fn drop(&mut self) {
|
||||
// This bridging link needs to be broken on Drop.
|
||||
unsafe {
|
||||
unsafe {
|
||||
msg_send![&*self.inner, setDelegate:nil];
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ extern fn will_close<T: AppDelegate>(this: &Object, _: Sel, _: id) {
|
|||
/// need to do.
|
||||
fn register_window_class<T: AppDelegate>() -> *const Class {
|
||||
static mut DELEGATE_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSObject").unwrap();
|
||||
|
|
@ -157,9 +157,9 @@ fn register_window_class<T: AppDelegate>() -> *const Class {
|
|||
|
||||
decl.add_ivar::<usize>(APP_PTR);
|
||||
decl.add_ivar::<usize>(WINDOW_MANAGER_ID);
|
||||
|
||||
|
||||
decl.add_method(sel!(windowWillClose:), will_close::<T> as extern fn(&Object, _, _));
|
||||
|
||||
|
||||
DELEGATE_CLASS = decl.register();
|
||||
});
|
||||
|
||||
|
|
|
|||
Reference in a new issue