Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions alchemy/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module implements the Application structure and associated
//! lifecycle methods. You typically never create this struct yourself;
//! This module implements the Application structure and associated
//! lifecycle methods. You typically never create this struct yourself;
//! in Alchemy, there's a global `shared_app` that you should use to work
//! with the `App` struct.
//!
Expand Down Expand Up @@ -28,7 +28,7 @@ impl AppDelegate for DefaultAppDelegate {}
/// also stored here for easy access.
pub struct App {
pub(crate) bridge: Mutex<Option<PlatformAppBridge>>,
pub delegate: Mutex<Box<AppDelegate>>,
pub delegate: Mutex<Box<dyn AppDelegate>>,
pub windows: WindowManager
}

Expand All @@ -54,7 +54,7 @@ impl App {
*bridge = Some(PlatformAppBridge::new(ptr));
}

/// Convenience method for registering one-off styles. Typically, you would want
/// Convenience method for registering one-off styles. Typically, you would want
/// to store your stylesheets as separate files, to enable hot-reloading - but it's
/// conceivable that you might want to just have them in your app, too, and this enables
/// that use case.
Expand Down Expand Up @@ -88,35 +88,35 @@ impl AppDelegate for App {
let mut delegate = self.delegate.lock().unwrap();
delegate.will_finish_launching();
}

/// Called when the application did finish launching.
fn did_finish_launching(&mut self) {
fn did_finish_launching(&mut self) {
let mut delegate = self.delegate.lock().unwrap();
delegate.did_finish_launching();
}

/// Called when the application will become active. We can use this, for instance,
/// to resume rendering cycles and so on.
/// Called when the application will become active. We can use this, for instance,
/// to resume rendering cycles and so on.
fn will_become_active(&mut self) {
let mut delegate = self.delegate.lock().unwrap();
delegate.will_become_active();
}

/// Called when the application did become active. We can use this, for instance,
/// Called when the application did become active. We can use this, for instance,
/// to resume rendering cycles and so on.
fn did_become_active(&mut self) {
let mut delegate = self.delegate.lock().unwrap();
delegate.did_become_active();
}

/// Called when the application will resigned active. We can use this, for instance,
/// Called when the application will resigned active. We can use this, for instance,
/// to pause rendering cycles and so on.
fn will_resign_active(&mut self) {
let mut delegate = self.delegate.lock().unwrap();
delegate.will_resign_active();
}

/// Called when the application has resigned active. We can use this, for instance,
/// Called when the application has resigned active. We can use this, for instance,
/// to pause rendering cycles and so on.
fn did_resign_active(&mut self) {
let mut delegate = self.delegate.lock().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions alchemy/src/components/fragment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A Fragment is for components that want to return or hoist multiple inner
//! child nodes. `impl IntoIterator` can't be used in trait returns right now,
//! and this API more or less matches what React presents, so I'm fine with it...
//! but as the language stabilizes even further I'd love to get rid of this and
//! but as the language stabilizes even further I'd love to get rid of this and
//! just allow returning arbitrary iterators.

use alchemy_lifecycle::ComponentKey;
Expand All @@ -12,7 +12,7 @@ pub struct FragmentProps;
/// Fragments are special - you can do something like the following in cases where you
/// want to render some views without requiring an intermediate view.
///
/// ```
/// ```ignore
/// <Fragment>
/// <View />
/// <View />
Expand All @@ -29,7 +29,7 @@ impl Fragment {
}

impl Props for Fragment {
fn set_props(&mut self, _: &mut std::any::Any) {}
fn set_props(&mut self, _: &mut dyn std::any::Any) {}
}

impl Component for Fragment {
Expand Down
12 changes: 6 additions & 6 deletions alchemy/src/components/text.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Handles hoisting per-platform specific Text components.
//! Each platform needs the freedom to do some specific things,
//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented
//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented
//! as bridges.

use std::sync::{Mutex};
Expand All @@ -22,7 +22,7 @@ pub struct TextProps;
///
/// Views accept styles and event callbacks as props. For example:
///
/// ```
/// ```ignore
/// <Text styles=["styleKey1", "styleKey2"] />
/// ```
pub struct Text(Mutex<PlatformTextBridge>);
Expand All @@ -38,7 +38,7 @@ impl Text {
}

impl Props for Text {
fn set_props(&mut self, _: &mut std::any::Any) {}
fn set_props(&mut self, _: &mut dyn std::any::Any) {}
}

impl Component for Text {
Expand All @@ -47,7 +47,7 @@ impl Component for Text {
}

fn has_native_backing_node(&self) -> bool { true }

fn borrow_native_backing_node(&self) -> Option<PlatformSpecificNodeType> {
let bridge = self.0.lock().unwrap();
Some(bridge.borrow_native_backing_node())
Expand Down Expand Up @@ -75,10 +75,10 @@ impl Component for Text {
RSX::VirtualText(s) => s.0.to_owned(),
_ => String::new()
}).collect::<String>();

let mut bridge = self.0.lock().unwrap();
bridge.set_text(text);

Ok(RSX::None)
}
}
8 changes: 4 additions & 4 deletions alchemy/src/components/view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Handles hoisting per-platform specific View components.
//! Each platform needs the freedom to do some specific things,
//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented
//! hence why they're all (somewhat annoyingly, but lovingly) re-implemented
//! as bridges.

use std::sync::Mutex;
Expand All @@ -24,7 +24,7 @@ pub struct ViewProps;
///
/// Views accept styles and event callbacks as props. For example:
///
/// ```
/// ```ignore
/// <View styles=["styleKey1", "styleKey2"] />
/// ```
pub struct View {
Expand All @@ -46,7 +46,7 @@ impl View {
}

impl Props for View {
fn set_props(&mut self, _: &mut std::any::Any) {}
fn set_props(&mut self, _: &mut dyn std::any::Any) {}
}

impl Component for View {
Expand All @@ -55,7 +55,7 @@ impl Component for View {
}

fn has_native_backing_node(&self) -> bool { true }

fn borrow_native_backing_node(&self) -> Option<PlatformSpecificNodeType> {
let bridge = self.bridge.lock().unwrap();
Some(bridge.borrow_native_backing_node())
Expand Down
6 changes: 3 additions & 3 deletions alchemy/src/window/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! right?
//!
//! There's also the fact that a user could opt to close a window. If that happens, we want to be
//! able to remove it from our structure... hence this manager that acts as a lightweight interface
//! able to remove it from our structure... hence this manager that acts as a lightweight interface
//! for managing per-platform Window instances.

use std::sync::{Arc, Mutex};
Expand All @@ -32,7 +32,7 @@ impl WindowManager {
/// Adds an `AppWindow` to this instance.
pub(crate) fn add(&self, window: Arc<Mutex<AppWindow>>) {
let mut windows = self.0.lock().unwrap();
if let None = windows.iter().position(|w| Arc::ptr_eq(&w, &window)) {
if windows.iter().position(|w| Arc::ptr_eq(&w, &window)).is_none() {
windows.push(window);
}
}
Expand All @@ -46,7 +46,7 @@ impl WindowManager {
let mut windows = self.0.lock().unwrap();
if let Some(index) = windows.iter().position(|window| {
let mut w = window.lock().unwrap();

if w.id == window_id {
w.delegate.will_close();
return true;
Expand Down
10 changes: 5 additions & 5 deletions alchemy/src/window/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct AppWindow {
pub title: String,
pub dimensions: (f64, f64, f64, f64),
pub bridge: PlatformWindowBridge,
pub delegate: Box<WindowDelegate>,
pub delegate: Box<dyn WindowDelegate>,
pub render_key: ComponentKey
}

Expand Down Expand Up @@ -92,7 +92,7 @@ impl Window {
let window_id = SHARED_APP.windows.allocate_new_window_id();
let view = View::default();
let shared_app_ptr: *const App = &**SHARED_APP;

// This unwrap() is fine, since we implement View ourselves in Alchemy
let backing_node = view.borrow_native_backing_node().unwrap();
let bridge = PlatformWindowBridge::new(window_id, backing_node, shared_app_ptr);
Expand All @@ -101,13 +101,13 @@ impl Window {
Ok(key) => key,
Err(_e) => { panic!("Uhhhh this really messed up"); }
};

Window(Arc::new(Mutex::new(AppWindow {
id: window_id,
style_keys: "".into(),
title: "".into(),
dimensions: (0., 0., 0., 0.),
bridge: bridge,
bridge,
delegate: Box::new(delegate),
render_key: key
})))
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Window {
/// Closes the window, unregistering it from the window manager in the process and ensuring the
/// necessary delegate method(s) are fired.
pub fn close(&self) {
let window_id = self.0.lock().unwrap().id;
let window_id = self.0.lock().unwrap().id;
SHARED_APP.windows.will_close(window_id);
let mut window = self.0.lock().unwrap();
window.close();
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cyclomatic-complexity-threshold = 30
cognitive-complexity-threshold = 30
doc-valid-idents = [
"MiB", "GiB", "TiB", "PiB", "EiB",
"DirectX", "OpenGL", "TrueType",
Expand Down
8 changes: 4 additions & 4 deletions cocoa/src/app.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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 {
Expand All @@ -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];
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions cocoa/src/text.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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)]
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);

Expand All @@ -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();
});

Expand Down
14 changes: 7 additions & 7 deletions cocoa/src/view.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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)]
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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);

Expand All @@ -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();
});

Expand Down
Loading