Merge pull request #45 from simlay/fix-cargo-test

Simplify CI, fix cargo test, and fix docstrings
This commit is contained in:
Ryan McGrath 2022-08-16 13:58:39 -07:00 committed by GitHub
commit ce0a8e5a48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 139 additions and 105 deletions

View file

@ -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
@ -45,55 +57,10 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --example animation
# Will exhibit linker warnings for 10.13 and below, expected:
- 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

View file

@ -53,3 +53,15 @@ 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"]

View file

@ -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) {
//!
//! }

View file

@ -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;

View file

@ -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

View file

@ -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<MenuItem>) -> Self {
Menu(unsafe {

View file

@ -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

View file

@ -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...
//! }
//!

View file

@ -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);

View file

@ -246,18 +246,12 @@ 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 +274,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 +296,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])
}

View file

@ -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<K: AsRef<str>>(&self, key: K) -> Option<Value> {

View file

@ -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

View file

@ -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);
//!

View file

@ -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);

View file

@ -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)]

View file

@ -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<T> ListView<T> {
/// `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<T> ListView<T> {
/// 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<MenuItem> {
/// let clicked_row = self.list_view.get_clicked_row_index();
///
@ -724,6 +734,9 @@ impl<T> ListView<T> {
/// // 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 {

View file

@ -6,11 +6,11 @@
//!
//! Views 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::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);

View file

@ -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::<YourAppDelegate, YourMessageType>::dispatch_main(your_message);
/// ```
///

View file

@ -6,8 +6,12 @@
//! tell it to stop).
//!
//! ```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);
//! ```

View file

@ -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);

View file

@ -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);
/// ```

View file

@ -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);
///

View file

@ -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!");
/// }

View file

@ -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;