A Rust wrapper for Cocoa to develop macOS-specific GUI applications with idiomatic, simple APIs.
Raw objc and cocoa crates require:
- Manual pointer management
- Verbose method calls
- Manual layout calculations
- No built-in styling system
- Steep learning curve
Cocoanut provides:
- β Builder Patterns - Fluent, chainable API
- β Layout System - Declarative VStack/HStack
- β Design System - Carbon Design System built-in
- β Type Safety - No raw pointers in public API
- β Simplicity - Learn macOS GUI development easily
let button = Button::new("Click")?;
button.set_title("Updated")?;
button.set_size(100.0, 50.0)?;
button.set_enabled(true)?;
window.add_subview(button, 10.0, 10.0, 100.0, 50.0)?;let button = Button::builder()
.title("Updated")
.size(100.0, 50.0)
.enabled(true)
.build()?;
let vstack = VStack::new()
.spacing(Spacing::standard())
.alignment(Alignment::Center);| Crate | Level | Safety | Learning Curve | Performance | Best For |
|---|---|---|---|---|---|
objc |
Very Low | Low | High | Highest | System programming |
objc2 |
Low | Medium | High | High | Performance-critical |
cocoa |
Medium | Medium | Medium | High | Legacy code |
cacao |
High | High | Low | Medium | Cross-platform apps |
cocoanut |
Low-Medium | High | Low | High | Learning & prototyping |
Recommendation: Start with Cocoanut to learn macOS GUI development in Rust!
cargo add cocoanutuse cocoanut::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a window
let window = Window::builder()
.title("My App")
.size(600.0, 400.0)
.center()
.build()?;
// Run the app - components display automatically!
app("MyApp")
.with_window(window)
.run()?;
Ok(())
}That's it! The app will display a window with Button, Label, and TextField components automatically.
Run it:
cargo run- β Builder Patterns - Fluent, chainable API
- β Layout System - VStack/HStack for composition
- β Carbon Design System - Professional styling
- β Window Management - Native macOS windows
- β Menu System - Application menus
- β Controls - Button, Label, TextField
- β Event Handling - User interactions
- β Drawing - Core Graphics integration
- β Type Safety - No raw pointers
- β Memory Safe - Rust ownership system
Run examples to see Cocoanut in action:
# Minimal app with components
cargo run --example minimal_app
# Basic window
cargo run --example basic_window
# Menu application
cargo run --example menu_app
# Comprehensive component demo
cargo run --example comprehensive_app
# Window builder patterns
cargo run --example window_builder_example
# Event binding example
cargo run --example event_binding_example
# Phase demos (Streamlit-inspired widgets)
cargo run --example phase1_display_demo
cargo run --example phase2_input_widgets_demo
cargo run --example phase3_advanced_layouts_demo
cargo run --example phase4_state_caching_demo
cargo run --example phase5_advanced_features_demoAll examples display real macOS GUI windows with interactive components. Press Cmd+Q to quit.
See docs/examples/EXAMPLES_AND_TESTS.md for complete examples guide.
- macOS 10.15 or later
- Rust 1.70 or later
- Xcode command line tools
cargo buildcargo run --example basic_window
cargo run --example menu_appcargo testContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Complete documentation is available:
Start here: DOCUMENTATION.md - Complete documentation index
- ARCHITECTURE.md - System architecture and design patterns
- TODO.md - Project roadmap and status
- SRC_ORGANIZATION.md - Source code structure
- MACOS_FEATURES.md - Native macOS features
- PERFORMANCE_OPTIMIZATION.md - Performance tuning
- MODULE_STANDARDIZATION.md - Module best practices
- docs/README.md - Documentation overview
- docs/guides/ - Feature guides and API reference
- docs/examples/ - Example documentation
- docs/archive/ - Historical documentation
- β
67 Streamlit-Inspired Widgets - Complete Phase 1-5 migration
- Phase 1: 21 display elements (Write, Text, Markdown, etc.)
- Phase 2: 21 input widgets (TextInput, Button, Checkbox, etc.)
- Phase 3: 12 layout containers (Columns, Tabs, Expander, etc.)
- Phase 4: 8 state & caching widgets (SessionState, DataCache, etc.)
- Phase 5: 5 advanced features (Navigation, CustomComponent, etc.)
- β
Macro Refactoring - 83 lines of boilerplate eliminated
- disabled_field!() macro for 12 widgets
- label_field!() macro for 5 widgets
- 282 tests passing (100%)
- β Trait-Based Architecture - Drawable, Textual, Positionable, Clickable traits
- β macOS Features - Native Feel, Accessibility, Dark Mode, Touch Bar, Continuity
- β Enhanced Examples - 4 unique purpose-built examples with different GUIs
- β Real macOS GUI - No mocking, full NSApplication support
- β Production Ready - Zero compilation errors, all tests passing
- Initial release
- Basic window management
- Menu system
- UI controls (Button, Label, TextField)
- Event handling
- Drawing utilities
- Comprehensive test suite