cocoanut 0.2.3

A minimal, declarative macOS GUI framework for Rust
//! Native Cocoa features showcase
//!
//! This example demonstrates the enhanced native Cocoa capabilities:
//! - Auto Layout with constraints
//! - Native view properties (shadows, layers, etc.)
//! - Additional native controls (SegmentedControl, ComboBox, SearchField, etc.)
//! - Responder chain management
//! - Animation support

use cocoanut::prelude::*;

fn main() -> Result<()> {
    // Register event callbacks
    event::register(1, || println!("✓ Segmented Control changed"));
    event::register(2, || println!("✓ Search field updated"));
    event::register(3, || println!("✓ Stepper value changed"));

    app("Native Cocoa Features")
        .size(900.0, 700.0)
        .build()
        .root(
            View::vstack()
                .child(
                    View::text("Enhanced Native Cocoa Features")
                        .bold()
                        .font_size(24.0)
                        .alignment(Alignment::Center),
                )
                .child(View::spacer())
                // Section 1: Auto Layout Example
                .child(
                    View::group_box("Auto Layout & Styling").child(
                        View::vstack()
                            .child(
                                View::text(
                                    "This view has shadow, corner radius, and layer backing",
                                )
                                .padding(10.0)
                                .shadow(5.0, 0.5, 2.0, 2.0)
                                .corner_radius(8.0)
                                .background("#f0f0f0")
                                .wants_layer(true),
                            )
                            .child(
                                View::button("Button with Custom Styling")
                                    .shadow(3.0, 0.3, 0.0, 2.0)
                                    .corner_radius(12.0),
                            ),
                    ),
                )
                .child(View::spacer())
                // Section 2: New Native Controls
                .child(
                    View::group_box("Additional Native Controls").child(
                        View::vstack()
                            .child(View::text("Segmented Control:"))
                            .child(
                                View::segmented_control(vec!["Option 1", "Option 2", "Option 3"])
                                    .on_click(1),
                            )
                            .child(View::spacer())
                            .child(View::text("Search Field:"))
                            .child(View::search_field("Type to search...").on_change(2))
                            .child(View::spacer())
                            .child(View::text("Combo Box:"))
                            .child(View::combo_box(vec!["Apple", "Banana", "Cherry", "Date"]))
                            .child(View::spacer())
                            .child(
                                View::hstack()
                                    .child(View::text("Stepper:"))
                                    .child(View::stepper(0.0, 100.0, 50.0).on_change(3)),
                            )
                            .child(View::spacer())
                            .child(View::text("Level Indicator:"))
                            .child(View::level_indicator(0.0, 100.0, 75.0)),
                    ),
                )
                .child(View::spacer())
                // Section 3: Advanced Features
                .child(
                    View::group_box("Advanced Features").child(
                        View::vstack()
                            .child(View::text("• Auto Layout support with NSLayoutConstraint"))
                            .child(View::text(
                                "• Native view properties (alpha, shadows, layers)",
                            ))
                            .child(View::text("• Responder chain management"))
                            .child(View::text("• Animation support"))
                            .child(View::text("• Pasteboard (clipboard) operations"))
                            .child(View::text("• Delegate patterns for TableView and more")),
                    ),
                )
                .child(View::spacer()),
        )
        .run()
}