Expand description

Wraps NSTextField and UITextField across platforms, explicitly as a TextField. In AppKit, NSTextField does double duty, and for clarity we just double the implementation.

TextFields 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::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(Color::rgb(224, 82, 99));
        self.label.set_text("LOL");
        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 an NSTextField/UITextField reference in the Objective-C runtime.

Traits

This trait can be used for implementing custom text field behavior.