docs.rs failed to build cocoanut-0.2.3
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.
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 minimal, declarative macOS GUI framework for Rust.
Why Cocoanut?
| Crate | Level | Safety | Learning Curve | Best For |
|---|---|---|---|---|
| objc | Low | Unsafe | Steep | Raw FFI |
| cocoa | Low | Unsafe | Steep | Raw AppKit |
| cacao | Mid | Safe | Medium | Cross-platform |
| cocoanut | High | Safe | Gentle | macOS native |
Quick Start
use *;
What's New in v0.3.0
Direct Closures
No more manual event ID management:
// Before (v0.2.0)
register;
button.on_click
// After (v0.3.0)
button.on_click_fn
State Helpers
let count = state;
count.increment; // +1
count.decrement; // -1
count.reset; // → 0
let text = state;
text.append;
text.clear;
let flag = state;
flag.toggle;
Styling DSL
use *;
let btn_style = style
.width
.height
.padding
.background
.foreground
.corner_radius;
button.styled
Component Macros
component!
stateful_component!
Async Support
button
.on_click_async
CLI Tool
# Install
&&
# Create new project
&&
# Development
Architecture
12 source files. ~4000 lines. 32 view types. Extensive unit tests. Type-safe APIs.
view.rs → View + ViewKind enum (the ONE core type)
renderer.rs → View tree → AppKit NSViews (single pass)
app.rs → App lifecycle + Appearance (dark mode)
event.rs → Callback registry + ObjC action handler
state.rs → Reactive State<T> + bind
menu.rs → Menu bar with action dispatch
layout.rs → Auto Layout support (NSLayoutConstraint)
native.rs → Native view properties & utilities
delegate.rs → Delegate patterns for native controls
component.rs → Component macros
style.rs → CSS-like styling DSL
async_support.rs → Async/await support
32 View Types
- Layout: VStack, HStack, ZStack, Spacer
- Text: Text, Label
- Controls: Button, TextField, SecureField, Checkbox, Radio, Slider, Toggle, Dropdown
- Extended: TextArea, DatePicker, ColorPicker
- Containers: ScrollView, TabView, SplitView, GroupBox, WebView, TableView
- Data: ProgressBar, Image
- Native Controls: SegmentedControl, ComboBox, SearchField, Stepper, LevelIndicator, PathControl
- Extensible: Custom
Features
Core Features
- Reactive State —
State<T>withon_changelisteners - Direct Closures —
on_click_fn(|| ...)without manual IDs - Event System —
event::register(id, closure)+ ObjC target/action dispatch - Dark Mode —
.dark()/.light()/set_appearance()at runtime - Accessibility —
.accessibility("label")on any view - Style Modifiers —
.width(),.bold(),.background(),.on_click() - CSS-like Styling —
style().width(100).padding(10).background("blue") - JSON Serializable —
ViewDescfor debugging/bridging
Native Cocoa Integration
- Auto Layout — NSLayoutConstraint support with type-safe API
- Native Properties — Direct access to shadows, layers, corner radius, opacity
- Responder Chain — First responder management and key view navigation
- Delegate Patterns — TableView data sources, TextField delegates
- Animation Support — Native AppKit animations
- Pasteboard — Clipboard operations (copy/paste)
- Window Management — Window level, alpha, background color
See NATIVE_COCOA_IMPROVEMENTS.md for detailed documentation.
Examples
Developing
cargo test — full library tests (AppKit stubs only under cfg(test)). cargo build --workspace includes the optional CLI crate.
License
Apache-2.0