From 8b43d43caf0640e49dbcb724c0337b670f293f70 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Wed, 17 Aug 2022 16:01:58 -0700 Subject: [PATCH 01/17] Block off AppKit animator proxy to fix iOS compiling --- src/layout/constraint.rs | 13 ++++++++++--- src/layout/mod.rs | 3 +++ src/view/mod.rs | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/layout/constraint.rs b/src/layout/constraint.rs index 13532399..91ecda91 100644 --- a/src/layout/constraint.rs +++ b/src/layout/constraint.rs @@ -10,6 +10,7 @@ use objc_id::ShareId; use crate::foundation::{id, NO, YES}; +#[cfg(all(feature = "appkit", target_os = "macos"))] use super::LayoutConstraintAnimatorProxy; /// A wrapper for `NSLayoutConstraint`. This both acts as a central path through which to activate @@ -31,18 +32,22 @@ pub struct LayoutConstraint { pub priority: f64, /// An animator proxy that can be used inside animation contexts. - pub animator: LayoutConstraintAnimatorProxy + /// This is currently only supported on macOS with the `appkit` feature. + #[cfg(all(feature = "appkit", target_os = "macos"))] + pub animator: LayoutConstraintAnimatorProxy, } impl LayoutConstraint { /// An internal method for wrapping existing constraints. pub(crate) fn new(object: id) -> Self { LayoutConstraint { + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: LayoutConstraintAnimatorProxy::new(object), + constraint: unsafe { ShareId::from_ptr(object) }, offset: 0.0, multiplier: 0.0, - priority: 0.0 + priority: 0.0, } } @@ -55,11 +60,13 @@ impl LayoutConstraint { } LayoutConstraint { + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: self.animator, + constraint: self.constraint, offset: offset, multiplier: self.multiplier, - priority: self.priority + priority: self.priority, } } diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 62d03925..38bafee4 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -6,7 +6,10 @@ mod traits; pub use traits::Layout; +#[cfg(all(feature = "appkit", target_os = "macos"))] mod animator; + +#[cfg(all(feature = "appkit", target_os = "macos"))] pub use animator::LayoutConstraintAnimatorProxy; #[cfg(feature = "autolayout")] diff --git a/src/view/mod.rs b/src/view/mod.rs index cc75c0e3..98c94666 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -58,7 +58,10 @@ use crate::layout::{LayoutAnchorDimension, LayoutAnchorX, LayoutAnchorY, SafeAre #[cfg(feature = "appkit")] use crate::pasteboard::PasteboardType; +#[cfg(all(feature = "appkit", target_os = "macos"))] mod animator; + +#[cfg(all(feature = "appkit", target_os = "macos"))] pub use animator::ViewAnimatorProxy; #[cfg_attr(feature = "appkit", path = "appkit.rs")] @@ -94,6 +97,9 @@ pub struct View { pub objc: ObjcProperty, /// An object that supports limited animations. Can be cloned into animation closures. + /// + /// This is currently only supported on macOS with the `appkit` feature. + #[cfg(all(feature = "appkit", target_os = "macos"))] pub animator: ViewAnimatorProxy, /// References the underlying layer. This is consistent across AppKit & UIKit - in AppKit @@ -145,7 +151,7 @@ pub struct View { /// A pointer to the Objective-C runtime center Y layout constraint. #[cfg(feature = "autolayout")] - pub center_y: LayoutAnchorY + pub center_y: LayoutAnchorY, } impl Default for View { @@ -209,8 +215,9 @@ impl View { layer: Layer::wrap(unsafe { msg_send![view, layer] }), + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: ViewAnimatorProxy::new(view), - objc: ObjcProperty::retain(view) + objc: ObjcProperty::retain(view), } } @@ -222,7 +229,7 @@ impl View { impl View where - T: ViewDelegate + 'static + T: ViewDelegate + 'static, { /// Initializes a new View with a given `ViewDelegate`. This enables you to respond to events /// and customize the view as a module, similar to class-based systems. @@ -256,6 +263,8 @@ impl View { is_handle: true, layer: self.layer.clone(), objc: self.objc.clone(), + + #[cfg(all(feature = "appkit", target_os = "macos"))] animator: self.animator.clone(), #[cfg(feature = "autolayout")] @@ -289,7 +298,7 @@ impl View { center_x: self.center_x.clone(), #[cfg(feature = "autolayout")] - center_y: self.center_y.clone() + center_y: self.center_y.clone(), } } From 66e1f91a6cf7bb196583d10a1a05d8c932f07faa Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Wed, 17 Aug 2022 16:02:51 -0700 Subject: [PATCH 02/17] Update README instructions for iOS beta to use correct name --- examples/ios-beta/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ios-beta/readme.md b/examples/ios-beta/readme.md index 5dc4a321..b0c45353 100644 --- a/examples/ios-beta/readme.md +++ b/examples/ios-beta/readme.md @@ -7,7 +7,7 @@ Since this needs to run in an iOS simulator or on a device, you can't run it lik - Start a simulator (Simulator.app). - `cargo install cargo-bundle` - `cargo bundle --example ios-beta --no-default-features --features uikit,autolayout --target x86_64-apple-ios` -- `xcrun simctl install booted target/x86_64-apple-ios/debug/examples/bundle/ios/cacao-ios-beta.app` +- `xcrun simctl install booted target/x86_64-apple-ios/debug/examples/bundle/ios/ios-beta.app` - `xcrun simctl launch --console booted com.cacao.ios-test` ## Current Support From cf11a935de2cde67d94a775c1d41955c8af416cd Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Wed, 17 Aug 2022 16:11:45 -0700 Subject: [PATCH 03/17] Formatting hell --- examples/animation.rs | 25 ++--- examples/autolayout.rs | 53 +++++----- examples/browser/main.rs | 98 +++++++++++-------- examples/browser/toolbar.rs | 6 +- examples/calculator/button_row.rs | 8 +- examples/calculator/calculator.rs | 6 +- examples/calculator/content_view.rs | 14 +-- examples/calculator/main.rs | 15 +-- examples/custom_image_drawing.rs | 29 +++--- examples/defaults.rs | 2 +- examples/frame_layout.rs | 55 ++++++----- examples/ios-beta/main.rs | 6 +- examples/text_input.rs | 76 ++++++++------ examples/todos_list/add/mod.rs | 2 +- examples/todos_list/add/view.rs | 6 +- examples/todos_list/app.rs | 2 +- examples/todos_list/menu.rs | 96 ++++++++++-------- examples/todos_list/preferences/advanced.rs | 4 +- examples/todos_list/preferences/general.rs | 6 +- examples/todos_list/preferences/mod.rs | 6 +- .../preferences/toggle_option_view.rs | 8 +- examples/todos_list/preferences/toolbar.rs | 4 +- examples/todos_list/storage/mod.rs | 2 +- examples/todos_list/storage/todos.rs | 10 +- examples/todos_list/todos/content_view.rs | 6 +- examples/todos_list/todos/list/mod.rs | 10 +- examples/todos_list/todos/list/row.rs | 6 +- examples/todos_list/todos/mod.rs | 4 +- examples/todos_list/windows.rs | 10 +- examples/webview_custom_protocol.rs | 17 ++-- examples/window.rs | 38 ++++--- examples/window_controller.rs | 47 +++++---- examples/window_delegate.rs | 47 +++++---- src/appkit/animation.rs | 4 +- src/appkit/app/delegate.rs | 84 ++++++++-------- src/appkit/app/enums.rs | 14 +-- src/appkit/app/mod.rs | 8 +- src/appkit/cursor.rs | 4 +- src/appkit/enums.rs | 6 +- src/appkit/event/mod.rs | 12 +-- src/appkit/menu/item.rs | 16 +-- src/appkit/menu/menu.rs | 59 ++++++----- src/appkit/printing/enums.rs | 4 +- src/appkit/printing/settings.rs | 4 +- src/appkit/toolbar/class.rs | 8 +- src/appkit/toolbar/enums.rs | 12 +-- src/appkit/toolbar/item.rs | 6 +- src/appkit/toolbar/mod.rs | 10 +- src/appkit/window/class.rs | 48 ++++----- src/appkit/window/config.rs | 6 +- src/appkit/window/controller/mod.rs | 4 +- src/appkit/window/enums.rs | 14 +-- src/appkit/window/mod.rs | 14 +-- src/button/enums.rs | 6 +- src/button/mod.rs | 8 +- src/cloudkit/share.rs | 4 +- src/color/appkit_dynamic_color.rs | 34 +++---- src/color/mod.rs | 22 ++--- src/control/mod.rs | 6 +- src/defaults/mod.rs | 2 +- src/defaults/value.rs | 30 +++--- src/dragdrop.rs | 10 +- src/error.rs | 4 +- src/events.rs | 8 +- src/filesystem/enums.rs | 12 +-- src/filesystem/save.rs | 4 +- src/filesystem/select.rs | 12 +-- src/foundation/autoreleasepool.rs | 2 +- src/foundation/class.rs | 4 +- src/foundation/mod.rs | 2 +- src/foundation/string.rs | 10 +- src/foundation/urls/bookmark_options.rs | 10 +- src/foundation/urls/mod.rs | 14 +-- src/foundation/urls/resource_keys.rs | 6 +- src/geometry.rs | 8 +- src/image/icons.rs | 10 +- src/image/image.rs | 22 ++--- src/image/mod.rs | 4 +- src/input/appkit.rs | 12 +-- src/input/mod.rs | 10 +- src/invoker.rs | 4 +- src/keys.rs | 2 +- src/layer/mod.rs | 6 +- src/layout/attributes.rs | 18 ++-- src/layout/dimension.rs | 6 +- src/layout/horizontal.rs | 6 +- src/layout/safe_guide.rs | 6 +- src/layout/vertical.rs | 6 +- src/listview/actions.rs | 6 +- src/listview/appkit.rs | 42 ++++---- src/listview/enums.rs | 8 +- src/listview/mod.rs | 12 +-- src/listview/row/appkit.rs | 24 ++--- src/listview/row/mod.rs | 14 +-- src/notification_center/name.rs | 4 +- src/pasteboard/mod.rs | 2 +- src/pasteboard/types.rs | 8 +- src/progress/enums.rs | 4 +- src/progress/mod.rs | 4 +- src/quicklook/config.rs | 12 +-- src/quicklook/mod.rs | 2 +- src/scrollview/appkit.rs | 24 ++--- src/scrollview/mod.rs | 10 +- src/select/mod.rs | 4 +- src/switch.rs | 4 +- src/text/enums.rs | 8 +- src/text/label/mod.rs | 10 +- src/uikit/app/delegate.rs | 4 +- src/uikit/app/mod.rs | 6 +- src/uikit/scene/delegate.rs | 6 +- src/uikit/scene/enums.rs | 8 +- src/user_notifications/enums.rs | 6 +- src/utils/cell_factory.rs | 8 +- src/utils/mod.rs | 6 +- src/utils/os.rs | 2 +- src/utils/properties.rs | 2 +- src/view/appkit.rs | 24 ++--- src/view/controller/mod.rs | 4 +- src/view/controller/uikit.rs | 4 +- src/view/splitviewcontroller/mod.rs | 16 +-- src/webview/actions.rs | 16 +-- src/webview/class.rs | 22 ++--- src/webview/config.rs | 4 +- src/webview/enums.rs | 18 ++-- src/webview/mimetype.rs | 8 +- src/webview/mod.rs | 8 +- 126 files changed, 932 insertions(+), 833 deletions(-) diff --git a/examples/animation.rs b/examples/animation.rs index 8d9de6cf..c5d2bc56 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -15,7 +15,7 @@ use cacao::appkit::{AnimationContext, App, AppDelegate}; use cacao::appkit::{Event, EventMask, EventMonitor}; struct BasicApp { - window: Window + window: Window, } impl AppDelegate for BasicApp { @@ -54,22 +54,22 @@ const ANIMATIONS: [[[f64; 5]; 4]; 3] = [ [44., 16., 100., 100., 1.], [128., 84., 144., 124., 1.], [32., 32., 44., 44., 0.7], - [328., 157., 200., 200., 0.7] + [328., 157., 200., 200., 0.7], ], // Red [ [44., 132., 100., 100., 1.], [40., 47., 80., 64., 0.7], [84., 220., 600., 109., 1.0], - [48., 600., 340., 44., 0.7] + [48., 600., 340., 44., 0.7], ], // Green [ [44., 248., 100., 100., 1.], [420., 232., 420., 244., 0.7], [310., 440., 150., 238., 0.7], - [32., 32., 44., 44., 1.] - ] + [32., 32., 44., 44., 1.], + ], ]; /// A helper method for generating frame constraints that we want to be animating. @@ -84,7 +84,7 @@ fn apply_styles(view: &View, parent: &View, background_color: Color, animation_t view.top.constraint_equal_to(&parent.top).offset(animation[0]), view.left.constraint_equal_to(&parent.left).offset(animation[1]), view.width.constraint_equal_to_constant(animation[2]), - view.height.constraint_equal_to_constant(animation[3]) + view.height.constraint_equal_to_constant(animation[3]), ] } @@ -94,7 +94,7 @@ struct AppWindow { blue: View, red: View, green: View, - key_monitor: Option + key_monitor: Option, } impl WindowDelegate for AppWindow { @@ -139,7 +139,7 @@ impl WindowDelegate for AppWindow { "a" => 1, "s" => 2, "d" => 3, - _ => 4 + _ => 4, }; if animation_index == 4 { @@ -170,8 +170,11 @@ impl WindowDelegate for AppWindow { } fn main() { - App::new("com.test.window", BasicApp { - window: Window::with(WindowConfig::default(), AppWindow::default()) - }) + App::new( + "com.test.window", + BasicApp { + window: Window::with(WindowConfig::default(), AppWindow::default()), + }, + ) .run(); } diff --git a/examples/autolayout.rs b/examples/autolayout.rs index 6bcdecdc..0fdb031e 100644 --- a/examples/autolayout.rs +++ b/examples/autolayout.rs @@ -10,29 +10,35 @@ use cacao::appkit::window::{Window, WindowConfig, WindowDelegate}; use cacao::appkit::{App, AppDelegate}; struct BasicApp { - window: Window + window: Window, } impl AppDelegate for BasicApp { fn did_finish_launching(&self) { App::set_menu(vec![ - Menu::new("", vec![ - MenuItem::Services, - MenuItem::Separator, - MenuItem::Hide, - MenuItem::HideOthers, - MenuItem::ShowAll, - MenuItem::Separator, - MenuItem::Quit, - ]), + Menu::new( + "", + vec![ + MenuItem::Services, + MenuItem::Separator, + MenuItem::Hide, + MenuItem::HideOthers, + MenuItem::ShowAll, + MenuItem::Separator, + MenuItem::Quit, + ], + ), Menu::new("File", vec![MenuItem::CloseWindow]), Menu::new("View", vec![MenuItem::EnterFullScreen]), - Menu::new("Window", vec![ - MenuItem::Minimize, - MenuItem::Zoom, - MenuItem::Separator, - MenuItem::new("Bring All to Front"), - ]), + Menu::new( + "Window", + vec![ + MenuItem::Minimize, + MenuItem::Zoom, + MenuItem::Separator, + MenuItem::new("Bring All to Front"), + ], + ), ]); App::activate(); @@ -50,7 +56,7 @@ struct AppWindow { content: View, blue: View, red: View, - green: View + green: View, } impl WindowDelegate for AppWindow { @@ -62,7 +68,7 @@ impl WindowDelegate for AppWindow { let dynamic = Color::dynamic(|style| match (style.theme, style.contrast) { (Theme::Dark, _) => Color::SystemGreen, - _ => Color::SystemRed + _ => Color::SystemRed, }); self.blue.set_background_color(Color::SystemBlue); @@ -89,14 +95,17 @@ impl WindowDelegate for AppWindow { self.green.leading.constraint_equal_to(&self.red.trailing).offset(16.), self.green.trailing.constraint_equal_to(&self.content.trailing).offset(-16.), self.green.bottom.constraint_equal_to(&self.content.bottom).offset(-16.), - self.green.width.constraint_equal_to_constant(100.) + self.green.width.constraint_equal_to_constant(100.), ]); } } fn main() { - App::new("com.test.window", BasicApp { - window: Window::with(WindowConfig::default(), AppWindow::default()) - }) + App::new( + "com.test.window", + BasicApp { + window: Window::with(WindowConfig::default(), AppWindow::default()), + }, + ) .run(); } diff --git a/examples/browser/main.rs b/examples/browser/main.rs index e6433fc9..44553176 100644 --- a/examples/browser/main.rs +++ b/examples/browser/main.rs @@ -16,7 +16,7 @@ use toolbar::BrowserToolbar; pub enum Action { Back, Forwards, - Load(String) + Load(String), } impl Action { @@ -26,39 +26,48 @@ impl Action { } struct BasicApp { - window: Window + window: Window, } impl AppDelegate for BasicApp { fn did_finish_launching(&self) { App::set_menu(vec![ - Menu::new("", vec![ - MenuItem::Services, - MenuItem::Separator, - MenuItem::Hide, - MenuItem::HideOthers, - MenuItem::ShowAll, - MenuItem::Separator, - MenuItem::Quit, - ]), + Menu::new( + "", + vec![ + MenuItem::Services, + MenuItem::Separator, + MenuItem::Hide, + MenuItem::HideOthers, + MenuItem::ShowAll, + MenuItem::Separator, + MenuItem::Quit, + ], + ), Menu::new("File", vec![MenuItem::CloseWindow]), - Menu::new("Edit", vec![ - MenuItem::Undo, - MenuItem::Redo, - MenuItem::Separator, - MenuItem::Cut, - MenuItem::Copy, - MenuItem::Paste, - MenuItem::Separator, - MenuItem::SelectAll, - ]), + Menu::new( + "Edit", + vec![ + MenuItem::Undo, + MenuItem::Redo, + MenuItem::Separator, + MenuItem::Cut, + MenuItem::Copy, + MenuItem::Paste, + MenuItem::Separator, + MenuItem::SelectAll, + ], + ), Menu::new("View", vec![MenuItem::EnterFullScreen]), - Menu::new("Window", vec![ - MenuItem::Minimize, - MenuItem::Zoom, - MenuItem::Separator, - MenuItem::new("Bring All to Front"), - ]), + Menu::new( + "Window", + vec![ + MenuItem::Minimize, + MenuItem::Zoom, + MenuItem::Separator, + MenuItem::new("Bring All to Front"), + ], + ), Menu::new("Help", vec![]), ]); @@ -83,7 +92,7 @@ impl Dispatcher for BasicApp { }, Action::Load(url) => { window.load_url(&url); - } + }, } } } @@ -95,14 +104,14 @@ impl WebViewDelegate for WebViewInstance {} struct AppWindow { toolbar: Toolbar, - content: WebView + content: WebView, } impl AppWindow { pub fn new() -> Self { AppWindow { toolbar: Toolbar::new("com.example.BrowserToolbar", BrowserToolbar::new()), - content: WebView::with(WebViewConfig::default(), WebViewInstance::default()) + content: WebView::with(WebViewConfig::default(), WebViewInstance::default()), } } @@ -128,18 +137,21 @@ impl WindowDelegate for AppWindow { } fn main() { - App::new("com.test.window", BasicApp { - window: Window::with( - { - let mut config = WindowConfig::default(); - - // This flag is necessary for Big Sur to use the correct toolbar style. - config.toolbar_style = WindowToolbarStyle::Expanded; - - config - }, - AppWindow::new() - ) - }) + App::new( + "com.test.window", + BasicApp { + window: Window::with( + { + let mut config = WindowConfig::default(); + + // This flag is necessary for Big Sur to use the correct toolbar style. + config.toolbar_style = WindowToolbarStyle::Expanded; + + config + }, + AppWindow::new(), + ), + }, + ) .run(); } diff --git a/examples/browser/toolbar.rs b/examples/browser/toolbar.rs index ecdbb6c3..fcdd8a31 100644 --- a/examples/browser/toolbar.rs +++ b/examples/browser/toolbar.rs @@ -27,7 +27,7 @@ pub struct BrowserToolbar { back_item: ToolbarItem, forwards_item: ToolbarItem, url_bar: TextField, - url_bar_item: ToolbarItem + url_bar_item: ToolbarItem, } impl BrowserToolbar { @@ -59,7 +59,7 @@ impl BrowserToolbar { back_item, forwards_item, url_bar, - url_bar_item + url_bar_item, } } @@ -100,7 +100,7 @@ impl ToolbarDelegate for BrowserToolbar { URL_BAR => &self.url_bar_item, _ => { std::unreachable!(); - } + }, } } } diff --git a/examples/calculator/button_row.rs b/examples/calculator/button_row.rs index 053c9bb1..3842c1c8 100644 --- a/examples/calculator/button_row.rs +++ b/examples/calculator/button_row.rs @@ -8,7 +8,7 @@ use crate::content_view::{button, BUTTON_HEIGHT, BUTTON_WIDTH}; pub struct ButtonRow { pub view: View, - pub buttons: Vec