Expand description

Wraps NSView and UIView across platforms.

This implementation errs towards the UIView side of things, and mostly acts as a wrapper to bring NSView to the modern era. It does this by flipping the coordinate system to be what people expect in 2020, and layer-backing all views by default.

Views implement Autolayout, which enable you to specify how things should appear on the screen.

use cacao::color::Color;;
use cacao::layout::{Layout, LayoutConstraint};
use cacao::view::View;
use cacao::appkit::window::{Window, WindowDelegate};

#[derive(Default)]
struct AppWindow {
    content: View,
    red: View,
    window: Window
}

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(Color::rgb(224, 82, 99));
        self.content.add_subview(&self.red);

        self.window.set_content_view(&self.content);

        LayoutConstraint::activate(&[
            self.red.top.constraint_equal_to(&self.content.top).offset(16.),
            self.red.leading.constraint_equal_to(&self.content.leading).offset(16.),
            self.red.trailing.constraint_equal_to(&self.content.trailing).offset(-16.),
            self.red.bottom.constraint_equal_to(&self.content.bottom).offset(-16.),
        ]);
    }
}

For more information on Autolayout, view the module or check out the examples folder.

Structs

A clone-able handler to a NS/UIScrollView reference in the Objective C runtime.

Traits

A ScrollViewDelegate implements methods that you might need or want to respond to. In addition to scroll-specific events, it enables implementing certain standard View handlers for things like drag and drop.