From 8bffc30ac14247b15f1c5335d54aeb9655ddc761 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 14 Aug 2022 15:44:53 -0400 Subject: [PATCH 1/8] fix cargo test --- examples/browser/main.rs | 29 +++++++++++++++++++---------- examples/ios-beta/main.rs | 5 +++++ examples/webview_custom_protocol.rs | 8 ++++++++ src/appkit/alert.rs | 4 ++-- src/appkit/app/mod.rs | 4 ++-- src/appkit/cursor.rs | 7 +++++++ src/appkit/menu/menu.rs | 8 ++++---- src/appkit/toolbar/enums.rs | 5 +++-- src/appkit/window/controller/mod.rs | 3 ++- src/button/mod.rs | 12 ++++++++++-- src/color/mod.rs | 24 +++++++++++------------- src/defaults/mod.rs | 10 ++++++---- src/foundation/class.rs | 2 +- src/input/mod.rs | 11 +++++++---- src/layer/mod.rs | 4 ++++ src/lib.rs | 2 +- src/listview/mod.rs | 19 ++++++++++++++++--- src/listview/row/mod.rs | 3 ++- src/notification_center/traits.rs | 2 +- src/progress/mod.rs | 2 +- src/scrollview/mod.rs | 7 ++++--- src/select/mod.rs | 5 +++++ src/text/label/mod.rs | 26 ++++++++++++++++---------- src/view/controller/mod.rs | 4 ++++ src/view/mod.rs | 5 +++-- 25 files changed, 144 insertions(+), 67 deletions(-) diff --git a/examples/browser/main.rs b/examples/browser/main.rs index e6433fc..80d2785 100644 --- a/examples/browser/main.rs +++ b/examples/browser/main.rs @@ -2,6 +2,7 @@ //! work with autolayout, and some basic ways to handle colors. use cacao::notification_center::Dispatcher; +#[cfg(feature = "webview")] use cacao::webview::{WebView, WebViewConfig, WebViewDelegate}; use cacao::appkit::menu::{Menu, MenuItem}; @@ -72,17 +73,20 @@ impl Dispatcher for BasicApp { fn on_ui_message(&self, message: Self::Message) { let window = self.window.delegate.as_ref().unwrap(); - let webview = &window.content; +#[cfg(feature = "webview")] + { + let webview = &window.content; - match message { - Action::Back => { - webview.go_back(); - }, - Action::Forwards => { - webview.go_forward(); - }, - Action::Load(url) => { - window.load_url(&url); + match message { + Action::Back => { + webview.go_back(); + }, + Action::Forwards => { + webview.go_forward(); + }, + Action::Load(url) => { + window.load_url(&url); + } } } } @@ -91,10 +95,12 @@ impl Dispatcher for BasicApp { #[derive(Default)] pub struct WebViewInstance; +#[cfg(feature = "webview")] impl WebViewDelegate for WebViewInstance {} struct AppWindow { toolbar: Toolbar, +#[cfg(feature = "webview")] content: WebView } @@ -102,12 +108,14 @@ impl AppWindow { pub fn new() -> Self { AppWindow { toolbar: Toolbar::new("com.example.BrowserToolbar", BrowserToolbar::new()), +#[cfg(feature = "webview")] content: WebView::with(WebViewConfig::default(), WebViewInstance::default()) } } pub fn load_url(&self, url: &str) { self.toolbar.delegate.as_ref().unwrap().set_url(url); +#[cfg(feature = "webview")] self.content.load_url(url); } } @@ -121,6 +129,7 @@ impl WindowDelegate for AppWindow { window.set_minimum_content_size(400., 400.); window.set_toolbar(&self.toolbar); +#[cfg(feature = "webview")] window.set_content_view(&self.content); self.load_url("https://www.duckduckgo.com/"); diff --git a/examples/ios-beta/main.rs b/examples/ios-beta/main.rs index 656f258..af9cfb5 100644 --- a/examples/ios-beta/main.rs +++ b/examples/ios-beta/main.rs @@ -1,5 +1,6 @@ use std::sync::RwLock; +#[cfg(targe_os = "ios")] use cacao::uikit::{App, AppDelegate, Scene, SceneConfig, SceneConnectionOptions, SceneSession, Window, WindowSceneDelegate}; use cacao::color::Color; @@ -9,6 +10,7 @@ use cacao::view::{View, ViewController, ViewDelegate}; #[derive(Default)] struct TestApp; +#[cfg(target_os= "ios")] impl AppDelegate for TestApp { fn config_for_scene_session(&self, session: SceneSession, _options: SceneConnectionOptions) -> SceneConfig { SceneConfig::new("Default Configuration", session.role()) @@ -55,10 +57,12 @@ impl ViewDelegate for RootView { #[derive(Default)] pub struct WindowScene { +#[cfg(target_os= "ios")] pub window: RwLock>, pub root_view_controller: RwLock>> } +#[cfg(target_os= "ios")] impl WindowSceneDelegate for WindowScene { fn will_connect(&self, scene: Scene, session: SceneSession, options: SceneConnectionOptions) { let bounds = scene.get_bounds(); @@ -80,5 +84,6 @@ impl WindowSceneDelegate for WindowScene { } fn main() { +#[cfg(target_os= "ios")] App::new(TestApp::default(), || Box::new(WindowScene::default())).run(); } diff --git a/examples/webview_custom_protocol.rs b/examples/webview_custom_protocol.rs index 7b326a8..fb97072 100644 --- a/examples/webview_custom_protocol.rs +++ b/examples/webview_custom_protocol.rs @@ -6,6 +6,7 @@ use cacao::appkit::toolbar::Toolbar; use cacao::appkit::window::{Window, WindowConfig, WindowDelegate, WindowToolbarStyle}; use cacao::appkit::{App, AppDelegate}; +#[cfg(feature = "webview")] use cacao::webview::{WebView, WebViewConfig, WebViewDelegate}; struct BasicApp { @@ -22,6 +23,7 @@ impl AppDelegate for BasicApp { #[derive(Default)] pub struct WebViewInstance; +#[cfg(feature = "webview")] impl WebViewDelegate for WebViewInstance { fn on_custom_protocol_request(&self, path: &str) -> Option> { let requested_asset_path = path.replace("cacao://", ""); @@ -62,9 +64,11 @@ impl WebViewDelegate for WebViewInstance { } struct AppWindow { +#[cfg(feature = "webview")] content: WebView } +#[cfg(feature = "webview")] impl AppWindow { pub fn new() -> Self { let mut webview_config = WebViewConfig::default(); @@ -82,6 +86,7 @@ impl AppWindow { } } +#[cfg(feature = "webview")] impl WindowDelegate for AppWindow { const NAME: &'static str = "WindowDelegate"; @@ -97,9 +102,12 @@ impl WindowDelegate for AppWindow { } } +#[cfg(feature = "webview")] fn main() { App::new("com.test.window", BasicApp { window: Window::with(WindowConfig::default(), AppWindow::new()) }) .run(); } +#[cfg(not(feature = "webview"))] +fn main() {} diff --git a/src/appkit/alert.rs b/src/appkit/alert.rs index 5076ecd..3483f30 100644 --- a/src/appkit/alert.rs +++ b/src/appkit/alert.rs @@ -7,13 +7,13 @@ //! If you want to show a complex view in an alert-esque fashion, you may consider looking at //! `Sheet`. //! -//! ```rust +//! ```rust,no_run //! use cacao::appkit::{App, AppDelegate, Alert}; //! //! #[derive(Default)] //! struct ExampleApp; //! -//! impl AppDelegate { +//! impl AppDelegate for ExampleApp { //! fn did_finish_launching(&self) { //! //! } diff --git a/src/appkit/app/mod.rs b/src/appkit/app/mod.rs index 3a7a321..4f41791 100644 --- a/src/appkit/app/mod.rs +++ b/src/appkit/app/mod.rs @@ -4,8 +4,8 @@ //! heavily by lifecycle events - in this case, your boilerplate would look something like this: //! //! ```rust,no_run -//! use cacao::app::{App, AppDelegate}; -//! use cacao::window::Window; +//! use cacao::appkit::{App, AppDelegate}; +//! use cacao::appkit::window::Window; //! //! #[derive(Default)] //! struct BasicApp; diff --git a/src/appkit/cursor.rs b/src/appkit/cursor.rs index 935880a..838f0d9 100644 --- a/src/appkit/cursor.rs +++ b/src/appkit/cursor.rs @@ -77,7 +77,14 @@ pub enum CursorType { /// For a very abbreviated example: /// /// ```rust,no_run +/// use cacao::appkit::Cursor; +/// use cacao::appkit::CursorType; +/// use cacao::dragdrop::DragInfo; +/// use cacao::dragdrop::DragOperation; +/// use cacao::view::ViewDelegate; +/// struct MyView; /// impl ViewDelegate for MyView { +/// const NAME: &'static str = "RootView"; /// fn dragging_entered(&self, _info: DragInfo) -> DragOperation { /// Cursor::push(CursorType::DragCopy); /// DragOperation::Copy diff --git a/src/appkit/menu/menu.rs b/src/appkit/menu/menu.rs index 8b9b3b9..8e22ff6 100644 --- a/src/appkit/menu/menu.rs +++ b/src/appkit/menu/menu.rs @@ -19,10 +19,10 @@ impl Menu { /// /// This method effectively does three things: /// - /// - Consumes the MenuItem Vec, and pulls out handlers we need to cache - /// - Configures the menu items appropriately, and wires them up - /// - Drops the values we no longer need, and returns only what's necessary - /// to get the menu functioning. + /// - Consumes the MenuItem Vec, and pulls out handlers we need to cache + /// - Configures the menu items appropriately, and wires them up + /// - Drops the values we no longer need, and returns only what's necessary + /// to get the menu functioning. /// pub fn new(title: &str, items: Vec) -> Self { Menu(unsafe { diff --git a/src/appkit/toolbar/enums.rs b/src/appkit/toolbar/enums.rs index 7a5bdd2..da94764 100644 --- a/src/appkit/toolbar/enums.rs +++ b/src/appkit/toolbar/enums.rs @@ -66,8 +66,9 @@ pub enum ItemIdentifier { /// /// For example: /// - /// ``` rust - /// vec![ItemIdentifier::ToggleSidebar, ItemIdentifier::SidebarTracker, ItemIdentifier::Print] + /// ``` rust,no_run + /// use cacao::appkit::toolbar::ItemIdentifier; + /// vec![ItemIdentifier::ToggleSidebar, ItemIdentifier::SidebarTracker, ItemIdentifier::Print]; /// ``` /// /// Would result in the toggle sidebar item showing up in the sidebar on the left, and the diff --git a/src/appkit/window/controller/mod.rs b/src/appkit/window/controller/mod.rs index cd573f8..0fbba82 100644 --- a/src/appkit/window/controller/mod.rs +++ b/src/appkit/window/controller/mod.rs @@ -12,13 +12,14 @@ //! # How to use //! //! ```rust,no_run -//! use cacao::appkit::app::AppDelegate; +//! use cacao::appkit::AppDelegate; //! use cacao::appkit::window::{WindowController, WindowDelegate}; //! //! #[derive(Default)] //! struct MyWindow; //! //! impl WindowDelegate for MyWindow { +//! const NAME: &'static str = "RootView"; //! // Your implementation here... //! } //! diff --git a/src/button/mod.rs b/src/button/mod.rs index bee3334..822fb5c 100644 --- a/src/button/mod.rs +++ b/src/button/mod.rs @@ -6,12 +6,16 @@ //! Some properties are platform-specific; see the documentation for further information. //! //! ```rust,no_run +//! use cacao::button::Button; +//! use cacao::view::View; +//! use crate::cacao::layout::Layout; //! let mut button = Button::new("My button title"); -//! button.set_text_equivalent("c"); +//! button.set_key_equivalent("c"); //! //! button.set_action(|| { //! println!("My button was clicked."); //! }); +//! let my_view : View<()> = todo!(); //! //! // Make sure you don't let your Button drop for as long as you need it. //! my_view.add_subview(&button); @@ -56,12 +60,16 @@ pub use enums::*; /// Some properties are platform-specific; see the documentation for further information. /// /// ```rust,no_run +/// use cacao::button::Button; +/// use cacao::view::View; +/// use crate::cacao::layout::Layout; /// let mut button = Button::new("My button title"); -/// button.set_text_equivalent("c"); +/// button.set_key_equivalent("c"); /// /// button.set_action(|| { /// println!("My button was clicked."); /// }); +/// let my_view : View<()> = todo!(); /// /// // Make sure you don't let your Button drop for as long as you need it. /// my_view.add_subview(&button); diff --git a/src/color/mod.rs b/src/color/mod.rs index 86d4074..2f0f70a 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -246,18 +246,16 @@ impl Color { let g = green as CGFloat / 255.0; let b = blue as CGFloat / 255.0; let a = alpha as CGFloat / 255.0; + #[cfg(feature = "appkit")] + let ptr = unsafe { + Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedRed:r green:g blue:b alpha:a]) + }; + #[cfg(all(feature = "uikit", not(feature = "appkit")))] + let ptr = unsafe { + Id::from_ptr(msg_send![class!(UIColor), colorWithRed:r green:g blue:b alpha:a]) + }; - Color::Custom(Arc::new(RwLock::new(unsafe { - #[cfg(feature = "appkit")] - { - Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedRed:r green:g blue:b alpha:a]) - } - - #[cfg(feature = "uikit")] - { - Id::from_ptr(msg_send![class!(UIColor), colorWithRed:r green:g blue:b alpha:a]) - } - }))) + Color::Custom(Arc::new(RwLock::new(ptr))) } /// Creates and returns a color in the RGB space, with the alpha level @@ -280,7 +278,7 @@ impl Color { Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedHue:h saturation:s brightness:b alpha:a]) } - #[cfg(feature = "uikit")] + #[cfg(all(feature = "uikit", not(feature = "appkit")))] { Id::from_ptr(msg_send![class!(UIColor), colorWithHue:h saturation:s brightness:b alpha:a]) } @@ -302,7 +300,7 @@ impl Color { Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedWhite:level alpha:alpha]) } - #[cfg(feature = "uikit")] + #[cfg(all(feature = "uikit", not(feature = "appkit")))] { Id::from_ptr(msg_send![class!(UIColor), colorWithWhite:level alpha:alpha]) } diff --git a/src/defaults/mod.rs b/src/defaults/mod.rs index 4f5c288..5e8d491 100644 --- a/src/defaults/mod.rs +++ b/src/defaults/mod.rs @@ -22,12 +22,13 @@ //! let mut defaults = UserDefaults::standard(); //! //! defaults.register({ -//! let map = HashMap::new(); +//! let mut map = HashMap::new(); //! map.insert("test", Value::string("value")); //! map //! }); //! -//! let value = defaults.get("test").unwrap().as_str().unwrap(); +//! let value = defaults.get("test").unwrap(); +//! let value = value.as_str().unwrap(); //! assert_eq!(value, "value"); //! ``` @@ -160,13 +161,14 @@ impl UserDefaults { /// Note that this also returns owned values, not references. `NSUserDefaults` explicitly /// returns new immutable copies each time, so we're free to vend them as such. /// - /// ```rust + /// ```rust,no_run /// use cacao::defaults::{UserDefaults, Value}; /// /// let mut defaults = UserDefaults::standard(); /// defaults.insert("test", Value::string("value")); /// - /// let value = defaults.get("test").unwrap().as_str().unwrap(); + /// let value = defaults.get("test").unwrap(); + /// let value = value.as_str().unwrap(); /// assert_eq!(value, "value"); /// ``` pub fn get>(&self, key: K) -> Option { diff --git a/src/foundation/class.rs b/src/foundation/class.rs index 0a0ca49..6dec898 100644 --- a/src/foundation/class.rs +++ b/src/foundation/class.rs @@ -15,7 +15,7 @@ lazy_static! { /// constantly calling into the runtime, we store pointers to Class types here after first lookup /// and/or creation. The general store format is (roughly speaking) as follows: /// -/// ```no_run +/// ```ignore /// { /// "subclass_type": { /// "superclass_type": *const Class as usize diff --git a/src/input/mod.rs b/src/input/mod.rs index 5490536..b4155e8 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -5,24 +5,27 @@ //! TextFields implement Autolayout, which enable you to specify how things should appear on the screen. //! //! ```rust,no_run -//! use cacao::color::rgb; +//! use cacao::color::Color; //! use cacao::layout::{Layout, LayoutConstraint}; -//! use cacao::view::TextField; -//! use cacao::window::{Window, WindowDelegate}; +//! use cacao::input::TextField; +//! use cacao::view::View; +//! use cacao::appkit::window::{Window, WindowDelegate}; //! //! #[derive(Default)] //! struct AppWindow { //! content: TextField, //! label: TextField, +//! red: View, //! window: Window //! } //! //! impl WindowDelegate for AppWindow { +//! const NAME: &'static str = "RootView"; //! fn did_load(&mut self, window: Window) { //! window.set_minimum_content_size(300., 300.); //! self.window = window; //! -//! self.label.set_background_color(rgb(224, 82, 99)); +//! self.label.set_background_color(Color::rgb(224, 82, 99)); //! self.label.set_text("LOL"); //! self.content.add_subview(&self.red); //! diff --git a/src/layer/mod.rs b/src/layer/mod.rs index 55399f4..5f849db 100644 --- a/src/layer/mod.rs +++ b/src/layer/mod.rs @@ -5,6 +5,8 @@ //! //! ```rust,no_run //! // Create a rounded red box +//! use cacao::view::View; +//! use cacao::color::Color; //! let view = View::default(); //! view.set_background_color(Color::SystemRed); //! view.layer.set_corner_radius(4.0); @@ -24,6 +26,8 @@ use crate::utils::properties::ObjcProperty; /// /// ```rust,no_run /// // Create a rounded red box +/// use cacao::view::View; +/// use cacao::color::Color; /// let view = View::default(); /// view.set_background_color(Color::SystemRed); /// view.layer.set_corner_radius(4.0); diff --git a/src/lib.rs b/src/lib.rs index cfc96ed..c32e5d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ //! # Hello World //! //! ```rust,no_run -//! use cacao::appkit::app::{App, AppDelegate}; +//! use cacao::appkit::{App, AppDelegate}; //! use cacao::appkit::window::Window; //! //! #[derive(Default)] diff --git a/src/listview/mod.rs b/src/listview/mod.rs index effac10..cf3a2b4 100644 --- a/src/listview/mod.rs +++ b/src/listview/mod.rs @@ -7,10 +7,10 @@ //! Views implement Autolayout, which enable you to specify how things should appear on the screen. //! //! ```rust,no_run -//! use cacao::color::rgb; +//! use cacao::color::Color; //! use cacao::layout::{Layout, LayoutConstraint}; //! use cacao::view::View; -//! use cacao::window::{Window, WindowDelegate}; +//! use cacao::appkit::window::{Window, WindowDelegate}; //! //! #[derive(Default)] //! struct AppWindow { @@ -20,11 +20,12 @@ //! } //! //! impl WindowDelegate for AppWindow { +//! const NAME: &'static str = "RootView"; //! fn did_load(&mut self, window: Window) { //! window.set_minimum_content_size(300., 300.); //! self.window = window; //! -//! self.red.set_background_color(rgb(224, 82, 99)); +//! self.red.set_background_color(Color::rgb(224, 82, 99)); //! self.content.add_subview(&self.red); //! //! self.window.set_content_view(&self.content); @@ -532,6 +533,9 @@ impl ListView { /// `reload_rows`, or `remove_rows` from there. /// /// ```rust,no_run + /// use cacao::listview::ListView; + /// use cacao::listview::RowAnimation; + /// let list_view: ListView<()> = todo!(); /// list_view.perform_batch_updates(|listview| { /// listview.insert_rows(&[0, 2], RowAnimation::SlideDown); /// }); @@ -712,7 +716,13 @@ impl ListView { /// For example (minus the other necessary ListViewDelegate pieces): /// /// ```rust,no_run + /// use cacao::appkit::menu::MenuItem; + /// use cacao::listview::{ListViewDelegate, ListView, ListViewRow}; + /// struct MyListView { + /// list_view: ListView<()>, + /// }; /// impl ListViewDelegate for MyListView { + /// const NAME: &'static str = "RootListView"; /// fn context_menu(&self) -> Vec { /// let clicked_row = self.list_view.get_clicked_row_index(); /// @@ -724,6 +734,9 @@ impl ListView { /// // User right-clicked on a row, so let's show an edit menu. /// vec![MenuItem::new("Edit")] /// } + /// fn did_load(&mut self, _: ListView) { todo!() } + /// fn number_of_items(&self) -> usize { todo!() } + /// fn item_for(&self, _: usize) -> ListViewRow { todo!() } /// } /// ``` pub fn get_clicked_row_index(&self) -> NSInteger { diff --git a/src/listview/row/mod.rs b/src/listview/row/mod.rs index b569e20..3bf43ba 100644 --- a/src/listview/row/mod.rs +++ b/src/listview/row/mod.rs @@ -6,7 +6,7 @@ //! //! Views implement Autolayout, which enable you to specify how things should appear on the screen. //! -//! ```rust,no_run +//! ```rust,compile_fail //! use cacao::color::rgb; //! use cacao::layout::{Layout, LayoutConstraint}; //! use cacao::view::View; @@ -20,6 +20,7 @@ //! } //! //! impl WindowDelegate for AppWindow { +//! const NAME: &'static str = "RootView"; //! fn did_load(&mut self, window: Window) { //! window.set_minimum_content_size(300., 300.); //! self.window = window; diff --git a/src/notification_center/traits.rs b/src/notification_center/traits.rs index 916e8c3..7e00dfa 100644 --- a/src/notification_center/traits.rs +++ b/src/notification_center/traits.rs @@ -4,7 +4,7 @@ /// performance, but is good enough for many applications. Implement this trait on your struct /// that implements `AppDelegate`, and then dispatch messages like the following: /// -/// ```rust,no_run +/// ```rust,compile_fail /// App::::dispatch_main(your_message); /// ``` /// diff --git a/src/progress/mod.rs b/src/progress/mod.rs index 4b4a5d3..fe2eeea 100644 --- a/src/progress/mod.rs +++ b/src/progress/mod.rs @@ -5,7 +5,7 @@ //! (where you have a fixed start and end) and indeterminate (infinite; it will go and go until you //! tell it to stop). //! -//! ```rust,no_run +//! ```rust,compile_fail //! let indicator = ProgressIndicator::new(); //! indicator.set_indeterminate(true); //! my_view.add_subview(&indicator); diff --git a/src/scrollview/mod.rs b/src/scrollview/mod.rs index 1ae0715..d975d81 100644 --- a/src/scrollview/mod.rs +++ b/src/scrollview/mod.rs @@ -7,10 +7,10 @@ //! Views implement Autolayout, which enable you to specify how things should appear on the screen. //! //! ```rust,no_run -//! use cacao::color::rgb; +//! use cacao::color::Color;; //! use cacao::layout::{Layout, LayoutConstraint}; //! use cacao::view::View; -//! use cacao::window::{Window, WindowDelegate}; +//! use cacao::appkit::window::{Window, WindowDelegate}; //! //! #[derive(Default)] //! struct AppWindow { @@ -20,11 +20,12 @@ //! } //! //! impl WindowDelegate for AppWindow { +//! const NAME: &'static str = "WindowDelegate"; //! fn did_load(&mut self, window: Window) { //! window.set_minimum_content_size(300., 300.); //! self.window = window; //! -//! self.red.set_background_color(rgb(224, 82, 99)); +//! self.red.set_background_color(Color::rgb(224, 82, 99)); //! self.content.add_subview(&self.red); //! //! self.window.set_content_view(&self.content); diff --git a/src/select/mod.rs b/src/select/mod.rs index 70ef03d..7eab27d 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -28,8 +28,13 @@ use crate::layout::{LayoutAnchorDimension, LayoutAnchorX, LayoutAnchorY}; /// Some properties are platform-specific; see the documentation for further information. /// /// ```rust,no_run +/// use cacao::select::Select; +/// use cacao::view::View; +/// use crate::cacao::layout::Layout; +/// /// let mut dropdown = Select::new(); /// +/// let my_view : View<()> = todo!(); /// // Make sure you don't let your Select drop for as long as you need it. /// my_view.add_subview(&dropdown); /// ``` diff --git a/src/text/label/mod.rs b/src/text/label/mod.rs index 4b0740b..bda7d8f 100644 --- a/src/text/label/mod.rs +++ b/src/text/label/mod.rs @@ -4,25 +4,28 @@ //! //! Labels implement Autolayout, which enable you to specify how things should appear on the screen. //! -//! ```rust,no_run -//! use cacao::color::rgb; +//! ```rust +//! use cacao::color::Color; //! use cacao::layout::{Layout, LayoutConstraint}; -//! use cacao::view::Label; -//! use cacao::window::{Window, WindowDelegate}; +//! use cacao::text::Label; +//! use cacao::view::View; +//! use cacao::appkit::window::{Window, WindowDelegate}; //! //! #[derive(Default)] //! struct AppWindow { //! content: Label, //! label: Label, +//! red: View, //! window: Window //! } //! //! impl WindowDelegate for AppWindow { +//! const NAME: &'static str = "RootView"; //! fn did_load(&mut self, window: Window) { //! window.set_minimum_content_size(300., 300.); //! self.window = window; //! -//! self.label.set_background_color(rgb(224, 82, 99)); +//! self.label.set_background_color(Color::rgb(224, 82, 99)); //! self.label.set_text("LOL"); //! self.content.add_subview(&self.red); //! @@ -107,25 +110,28 @@ fn allocate_view(registration_fn: fn() -> *const Class) -> id { /// /// Labels implement Autolayout, which enable you to specify how things should appear on the screen. /// -/// ```rust,no_run -/// use cacao::color::rgb; +/// ```rust +/// use cacao::color::Color; /// use cacao::layout::{Layout, LayoutConstraint}; -/// use cacao::view::Label; -/// use cacao::window::{Window, WindowDelegate}; +/// use cacao::text::Label; +/// use cacao::appkit::window::{Window, WindowDelegate}; +/// use cacao::view::View; /// /// #[derive(Default)] /// struct AppWindow { /// content: Label, /// label: Label, +/// red: View, /// window: Window /// } /// /// impl WindowDelegate for AppWindow { +/// const NAME: &'static str = "RootView"; /// fn did_load(&mut self, window: Window) { /// window.set_minimum_content_size(300., 300.); /// self.window = window; /// -/// self.label.set_background_color(rgb(224, 82, 99)); +/// self.label.set_background_color(Color::rgb(224, 82, 99)); /// self.label.set_text("LOL"); /// self.content.add_subview(&self.red); /// diff --git a/src/view/controller/mod.rs b/src/view/controller/mod.rs index e135e68..70a429e 100644 --- a/src/view/controller/mod.rs +++ b/src/view/controller/mod.rs @@ -22,9 +22,13 @@ mod native_interface; /// /// ## Example /// ```rust,no_run +/// use cacao::view::ViewDelegate; +/// /// struct ContentViewDelegate; /// /// impl ViewDelegate for ContentViewDelegate { +/// const NAME: &'static str = "ContentViewDelegate"; +/// /// fn will_appear(&self, animated: bool) { /// println!("This controller is about to appear!"); /// } diff --git a/src/view/mod.rs b/src/view/mod.rs index 02cd41a..cc75c0e 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -6,11 +6,11 @@ //! //! Views implement Autolayout, which enable you to specify how things should appear on the screen. //! -//! ```rust,no_run +//! ```rust //! use cacao::color::Color; //! use cacao::layout::{Layout, LayoutConstraint}; //! use cacao::view::View; -//! use cacao::window::{Window, WindowDelegate}; +//! use cacao::appkit::window::{Window, WindowDelegate}; //! //! #[derive(Default)] //! struct AppWindow { @@ -20,6 +20,7 @@ //! } //! //! impl WindowDelegate for AppWindow { +//! const NAME: &'static str = "RootView"; //! fn did_load(&mut self, window: Window) { //! window.set_minimum_content_size(300., 300.); //! self.window = window; From db8af85fedd67333e6de029fc42adf4e7836398d Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 14 Aug 2022 15:48:50 -0400 Subject: [PATCH 2/8] Simplify CI steps --- .github/workflows/ci.yml | 46 ++-------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 986b94b..c1a9503 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,56 +44,14 @@ jobs: override: true - uses: actions-rs/cargo@v1 with: - command: build - args: --example animation - # Will exhibit linker warnings for 10.13 and below, expected: + command: test - uses: actions-rs/cargo@v1 with: command: build - args: --example autolayout - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example calculator - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example custom_image_drawing - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example defaults - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example frame_layout + args: --features webview --example webview_custom_protocol # fails because it needs uikit, which is not # building for me #- uses: actions-rs/cargo@v1 # with: # command: build # args: --example ios-beta - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example text_input - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example todos_list - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example window - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example window_controller - - uses: actions-rs/cargo@v1 - with: - command: build - args: --example window_delegate - - uses: actions-rs/cargo@v1 - with: - command: build - args: --features webview --example webview_custom_protocol From 7c917ee0ea6d4f872a251272f0622b86bfe47c5d Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 14 Aug 2022 15:59:05 -0400 Subject: [PATCH 3/8] Removed some compile_fail parts --- src/listview/row/mod.rs | 4 ++-- src/progress/mod.rs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/listview/row/mod.rs b/src/listview/row/mod.rs index 3bf43ba..c9471ff 100644 --- a/src/listview/row/mod.rs +++ b/src/listview/row/mod.rs @@ -7,7 +7,7 @@ //! Views implement Autolayout, which enable you to specify how things should appear on the screen. //! //! ```rust,compile_fail -//! use cacao::color::rgb; +//! use cacao::color::Color; //! use cacao::layout::{Layout, LayoutConstraint}; //! use cacao::view::View; //! use cacao::window::{Window, WindowDelegate}; @@ -25,7 +25,7 @@ //! window.set_minimum_content_size(300., 300.); //! self.window = window; //! -//! self.red.set_background_color(rgb(224, 82, 99)); +//! self.red.set_background_color(Color::rgb(224, 82, 99)); //! self.content.add_subview(&self.red); //! //! self.window.set_content_view(&self.content); diff --git a/src/progress/mod.rs b/src/progress/mod.rs index fe2eeea..90ef3a0 100644 --- a/src/progress/mod.rs +++ b/src/progress/mod.rs @@ -5,9 +5,13 @@ //! (where you have a fixed start and end) and indeterminate (infinite; it will go and go until you //! tell it to stop). //! -//! ```rust,compile_fail +//! ```rust,no_run +//! use cacao::progress::ProgressIndicator; +//! use cacao::view::View; +//! use crate::cacao::layout::Layout; //! let indicator = ProgressIndicator::new(); //! indicator.set_indeterminate(true); +//! let my_view : View<()> = todo!(); //! my_view.add_subview(&indicator); //! ``` From b0b93468d81ad9f45b6516e6c56a395de2a856d8 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 14 Aug 2022 16:06:53 -0400 Subject: [PATCH 4/8] Fixed indents on feature flagged compiling of examples --- examples/browser/main.rs | 10 +++++----- examples/ios-beta/main.rs | 4 ++-- examples/webview_custom_protocol.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/browser/main.rs b/examples/browser/main.rs index 80d2785..4fa0325 100644 --- a/examples/browser/main.rs +++ b/examples/browser/main.rs @@ -73,7 +73,7 @@ impl Dispatcher for BasicApp { fn on_ui_message(&self, message: Self::Message) { let window = self.window.delegate.as_ref().unwrap(); -#[cfg(feature = "webview")] + #[cfg(feature = "webview")] { let webview = &window.content; @@ -100,7 +100,7 @@ impl WebViewDelegate for WebViewInstance {} struct AppWindow { toolbar: Toolbar, -#[cfg(feature = "webview")] + #[cfg(feature = "webview")] content: WebView } @@ -108,14 +108,14 @@ impl AppWindow { pub fn new() -> Self { AppWindow { toolbar: Toolbar::new("com.example.BrowserToolbar", BrowserToolbar::new()), -#[cfg(feature = "webview")] + #[cfg(feature = "webview")] content: WebView::with(WebViewConfig::default(), WebViewInstance::default()) } } pub fn load_url(&self, url: &str) { self.toolbar.delegate.as_ref().unwrap().set_url(url); -#[cfg(feature = "webview")] + #[cfg(feature = "webview")] self.content.load_url(url); } } @@ -129,7 +129,7 @@ impl WindowDelegate for AppWindow { window.set_minimum_content_size(400., 400.); window.set_toolbar(&self.toolbar); -#[cfg(feature = "webview")] + #[cfg(feature = "webview")] window.set_content_view(&self.content); self.load_url("https://www.duckduckgo.com/"); diff --git a/examples/ios-beta/main.rs b/examples/ios-beta/main.rs index af9cfb5..cc728a1 100644 --- a/examples/ios-beta/main.rs +++ b/examples/ios-beta/main.rs @@ -57,7 +57,7 @@ impl ViewDelegate for RootView { #[derive(Default)] pub struct WindowScene { -#[cfg(target_os= "ios")] + #[cfg(target_os= "ios")] pub window: RwLock>, pub root_view_controller: RwLock>> } @@ -84,6 +84,6 @@ impl WindowSceneDelegate for WindowScene { } fn main() { -#[cfg(target_os= "ios")] + #[cfg(target_os= "ios")] App::new(TestApp::default(), || Box::new(WindowScene::default())).run(); } diff --git a/examples/webview_custom_protocol.rs b/examples/webview_custom_protocol.rs index fb97072..7fd5a27 100644 --- a/examples/webview_custom_protocol.rs +++ b/examples/webview_custom_protocol.rs @@ -64,7 +64,7 @@ impl WebViewDelegate for WebViewInstance { } struct AppWindow { -#[cfg(feature = "webview")] + #[cfg(feature = "webview")] content: WebView } From d0d99df147b176cdd25434f0980e50282b691b9a Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 14 Aug 2022 16:40:38 -0400 Subject: [PATCH 5/8] Updates from comments --- .github/workflows/ci.yml | 15 ++++++++++++--- Cargo.toml | 11 +++++++++++ examples/browser/main.rs | 29 ++++++++++------------------- examples/ios-beta/main.rs | 5 ----- examples/webview_custom_protocol.rs | 5 ----- src/listview/row/mod.rs | 4 ++-- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1a9503..e62c876 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,18 @@ jobs: with: command: fmt args: -- --check + test: + name: Check that examples build + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: test build: name: Check that the code builds runs-on: macos-latest @@ -42,9 +54,6 @@ jobs: with: toolchain: stable override: true - - uses: actions-rs/cargo@v1 - with: - command: test - uses: actions-rs/cargo@v1 with: command: build diff --git a/Cargo.toml b/Cargo.toml index dd94ba9..020a3e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,3 +53,14 @@ identifier = "com.cacao.ios-test" category = "Developer Tool" short_description = "An example Cacao iOS app." long_description = "An example Cacao iOS app." + +[[example]] +name = "webview_custom_protocol" +required-features = ["webview"] + +[[example]] +name = "browser" +required-features = ["webview"] +[[example]] +name = "ios-beta" +required-features = ["uikit", "autolayout"] diff --git a/examples/browser/main.rs b/examples/browser/main.rs index 4fa0325..e6433fc 100644 --- a/examples/browser/main.rs +++ b/examples/browser/main.rs @@ -2,7 +2,6 @@ //! work with autolayout, and some basic ways to handle colors. use cacao::notification_center::Dispatcher; -#[cfg(feature = "webview")] use cacao::webview::{WebView, WebViewConfig, WebViewDelegate}; use cacao::appkit::menu::{Menu, MenuItem}; @@ -73,20 +72,17 @@ impl Dispatcher for BasicApp { fn on_ui_message(&self, message: Self::Message) { let window = self.window.delegate.as_ref().unwrap(); - #[cfg(feature = "webview")] - { - let webview = &window.content; + let webview = &window.content; - match message { - Action::Back => { - webview.go_back(); - }, - Action::Forwards => { - webview.go_forward(); - }, - Action::Load(url) => { - window.load_url(&url); - } + match message { + Action::Back => { + webview.go_back(); + }, + Action::Forwards => { + webview.go_forward(); + }, + Action::Load(url) => { + window.load_url(&url); } } } @@ -95,12 +91,10 @@ impl Dispatcher for BasicApp { #[derive(Default)] pub struct WebViewInstance; -#[cfg(feature = "webview")] impl WebViewDelegate for WebViewInstance {} struct AppWindow { toolbar: Toolbar, - #[cfg(feature = "webview")] content: WebView } @@ -108,14 +102,12 @@ impl AppWindow { pub fn new() -> Self { AppWindow { toolbar: Toolbar::new("com.example.BrowserToolbar", BrowserToolbar::new()), - #[cfg(feature = "webview")] content: WebView::with(WebViewConfig::default(), WebViewInstance::default()) } } pub fn load_url(&self, url: &str) { self.toolbar.delegate.as_ref().unwrap().set_url(url); - #[cfg(feature = "webview")] self.content.load_url(url); } } @@ -129,7 +121,6 @@ impl WindowDelegate for AppWindow { window.set_minimum_content_size(400., 400.); window.set_toolbar(&self.toolbar); - #[cfg(feature = "webview")] window.set_content_view(&self.content); self.load_url("https://www.duckduckgo.com/"); diff --git a/examples/ios-beta/main.rs b/examples/ios-beta/main.rs index cc728a1..656f258 100644 --- a/examples/ios-beta/main.rs +++ b/examples/ios-beta/main.rs @@ -1,6 +1,5 @@ use std::sync::RwLock; -#[cfg(targe_os = "ios")] use cacao::uikit::{App, AppDelegate, Scene, SceneConfig, SceneConnectionOptions, SceneSession, Window, WindowSceneDelegate}; use cacao::color::Color; @@ -10,7 +9,6 @@ use cacao::view::{View, ViewController, ViewDelegate}; #[derive(Default)] struct TestApp; -#[cfg(target_os= "ios")] impl AppDelegate for TestApp { fn config_for_scene_session(&self, session: SceneSession, _options: SceneConnectionOptions) -> SceneConfig { SceneConfig::new("Default Configuration", session.role()) @@ -57,12 +55,10 @@ impl ViewDelegate for RootView { #[derive(Default)] pub struct WindowScene { - #[cfg(target_os= "ios")] pub window: RwLock>, pub root_view_controller: RwLock>> } -#[cfg(target_os= "ios")] impl WindowSceneDelegate for WindowScene { fn will_connect(&self, scene: Scene, session: SceneSession, options: SceneConnectionOptions) { let bounds = scene.get_bounds(); @@ -84,6 +80,5 @@ impl WindowSceneDelegate for WindowScene { } fn main() { - #[cfg(target_os= "ios")] App::new(TestApp::default(), || Box::new(WindowScene::default())).run(); } diff --git a/examples/webview_custom_protocol.rs b/examples/webview_custom_protocol.rs index 7fd5a27..5a8a3f9 100644 --- a/examples/webview_custom_protocol.rs +++ b/examples/webview_custom_protocol.rs @@ -6,7 +6,6 @@ use cacao::appkit::toolbar::Toolbar; use cacao::appkit::window::{Window, WindowConfig, WindowDelegate, WindowToolbarStyle}; use cacao::appkit::{App, AppDelegate}; -#[cfg(feature = "webview")] use cacao::webview::{WebView, WebViewConfig, WebViewDelegate}; struct BasicApp { @@ -86,7 +85,6 @@ impl AppWindow { } } -#[cfg(feature = "webview")] impl WindowDelegate for AppWindow { const NAME: &'static str = "WindowDelegate"; @@ -102,12 +100,9 @@ impl WindowDelegate for AppWindow { } } -#[cfg(feature = "webview")] fn main() { App::new("com.test.window", BasicApp { window: Window::with(WindowConfig::default(), AppWindow::new()) }) .run(); } -#[cfg(not(feature = "webview"))] -fn main() {} diff --git a/src/listview/row/mod.rs b/src/listview/row/mod.rs index c9471ff..7ed7208 100644 --- a/src/listview/row/mod.rs +++ b/src/listview/row/mod.rs @@ -6,11 +6,11 @@ //! //! Views implement Autolayout, which enable you to specify how things should appear on the screen. //! -//! ```rust,compile_fail +//! ```rust //! use cacao::color::Color; //! use cacao::layout::{Layout, LayoutConstraint}; //! use cacao::view::View; -//! use cacao::window::{Window, WindowDelegate}; +//! use cacao::appkit::window::{Window, WindowDelegate}; //! //! #[derive(Default)] //! struct AppWindow { From 466d64542e2f170b1c06b709df08d95d861d81d8 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 14 Aug 2022 16:49:49 -0400 Subject: [PATCH 6/8] Removed feature cfg from examples --- examples/webview_custom_protocol.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/webview_custom_protocol.rs b/examples/webview_custom_protocol.rs index 5a8a3f9..7b326a8 100644 --- a/examples/webview_custom_protocol.rs +++ b/examples/webview_custom_protocol.rs @@ -22,7 +22,6 @@ impl AppDelegate for BasicApp { #[derive(Default)] pub struct WebViewInstance; -#[cfg(feature = "webview")] impl WebViewDelegate for WebViewInstance { fn on_custom_protocol_request(&self, path: &str) -> Option> { let requested_asset_path = path.replace("cacao://", ""); @@ -63,11 +62,9 @@ impl WebViewDelegate for WebViewInstance { } struct AppWindow { - #[cfg(feature = "webview")] content: WebView } -#[cfg(feature = "webview")] impl AppWindow { pub fn new() -> Self { let mut webview_config = WebViewConfig::default(); From a8e96836a234b714b4c5171159e76c20ef108ae1 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sun, 14 Aug 2022 16:50:40 -0400 Subject: [PATCH 7/8] Add extra line in cargo --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 020a3e7..ba54d08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ required-features = ["webview"] [[example]] name = "browser" required-features = ["webview"] + [[example]] name = "ios-beta" required-features = ["uikit", "autolayout"] From e38d56ee4290c59c7e0725726a6dfbb8a0a2a0bb Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Tue, 16 Aug 2022 09:34:48 -0400 Subject: [PATCH 8/8] fix fmt --- src/color/mod.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/color/mod.rs b/src/color/mod.rs index 2f0f70a..0f46cd2 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -247,13 +247,9 @@ impl Color { let b = blue as CGFloat / 255.0; let a = alpha as CGFloat / 255.0; #[cfg(feature = "appkit")] - let ptr = unsafe { - Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedRed:r green:g blue:b alpha:a]) - }; + let ptr = unsafe { Id::from_ptr(msg_send![class!(NSColor), colorWithCalibratedRed:r green:g blue:b alpha:a]) }; #[cfg(all(feature = "uikit", not(feature = "appkit")))] - let ptr = unsafe { - Id::from_ptr(msg_send![class!(UIColor), colorWithRed:r green:g blue:b alpha:a]) - }; + let ptr = unsafe { Id::from_ptr(msg_send![class!(UIColor), colorWithRed:r green:g blue:b alpha:a]) }; Color::Custom(Arc::new(RwLock::new(ptr))) }