Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
🥥 Cocoanut
A Rust wrapper for Cocoa to develop macOS-specific GUI applications with idiomatic, simple APIs.
Why Cocoanut?
The Problem
Raw objc and cocoa crates require:
- Manual pointer management
- Verbose method calls
- Manual layout calculations
- No built-in styling system
- Steep learning curve
The Solution
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
Simplicity in Action
Before (objc/cocoa)
let button = new?;
button.set_title?;
button.set_size?;
button.set_enabled?;
window.add_subview?;
After (Cocoanut)
let button = builder
.title
.size
.enabled
.build?;
let vstack = new
.spacing
.alignment;
Comparison Table
| 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!
Quick Start
use *;
That's it! The app will display a window with Button, Label, and TextField components automatically.
Run it:
Features
- ✅ 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
Examples
Run examples to see Cocoanut in action:
# Minimal app with components
# Basic window
# Menu application
# Comprehensive component demo
# Layout & Containers Demo - Educational overview
# Layout Patterns Demo - Real-world patterns
# Containers with Borders Demo - Visual container demonstration
All examples display real macOS GUI windows with interactive components. Press Cmd+Q to quit.
Layout & Containers Demos:
- docs/VISUAL_LAYOUT_DEMO.md - Visual GUI with 50+ interactive components
- docs/CONTAINERS_WITH_BORDERS.md - Containers with visual borders (NEW)
- docs/LAYOUT_CONTAINERS_DEMO.md - Comprehensive layout guide
See docs/EXAMPLES_AND_TESTS.md for all examples.
Requirements
- macOS 10.15 or later
- Rust 1.70 or later
- Xcode command line tools
Building
Running Examples
Testing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Changelog
0.2.0 (Current)
- ✅ GUI Components Display - Button, Label, TextField now show in windows
- ✅ SimpleApp API - Minimal boilerplate app creation
- ✅ Window Builder - Fluent window configuration
- ✅ Component Positioning - Automatic layout in windows
- ✅ Real macOS GUI - No mocking, full NSApplication support
📚 Documentation
Complete documentation is available in DOCUMENTATION.md. Key guides:
- ARCHITECTURE.md - System architecture and design
- SRC_ORGANIZATION.md - Source code structure
- MACOS_FEATURES.md - Native macOS features
- SIMPLE_APP_API.md - High-level API guide
- EXAMPLES_UPDATED.md - Available examples
📋 Changelog
0.2.0
- ✅ Trait-Based Architecture - Drawable, Textual, Positionable traits
- ✅ macOS Features - Native Feel, Accessibility, Dark Mode, Touch Bar, Continuity
- ✅ Priority Features - 15 features across 3 priority levels
- ✅ Source Organization - Hierarchical module structure
- ✅ Component Positioning - Automatic layout in windows
- ✅ Real macOS GUI - No mocking, full NSApplication support
0.1.0
- Initial release
- Basic window management
- Menu system
- UI controls (Button, Label, TextField)
- Event handling
- Drawing utilities
- Comprehensive test suite