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 = "RootView";
fn did_load(&mut self, window: Window) {
window.set_minimum_content_size(300., 300.);
self.window = window;
self.red.set_background_color(Color::SystemRed);
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 SplitViewController manages two or more view controllers in a split-pane view.
A clone-able handler to a ViewController
reference in the Objective C runtime. We use this
instead of a stock View
for easier recordkeeping, since it’ll need to hold the View
on that
side anyway.
A wrapper for an animation proxy object in Cocoa that supports basic animations.
A ViewController
is a wrapper around NSViewController
in AppKit, and UIViewController
in
UIKit
Traits
This trait can be used for implementing custom View behavior. You implement this trait on your
struct, and wrap your struct in a View
or ViewController
. The view or controller then
handles interfacing between your struct and system events.