core_animation/lib.rs
1//! Rust bindings for macOS Core Animation with ergonomic builder APIs.
2//!
3//! # Builders
4//!
5//! | Builder | Purpose |
6//! |---------|---------|
7//! | [`WindowBuilder`] | Layer-backed windows with background, border, transparency |
8//! | [`CALayerBuilder`] | Base layers with bounds, position, sublayers |
9//! | [`CAShapeLayerBuilder`] | Vector shapes with path, fill, stroke, shadows |
10//! | [`CATextLayerBuilder`] | Text rendering layers |
11//! | [`CAEmitterLayerBuilder`](particles::CAEmitterLayerBuilder) | Particle systems with closure-based cell configuration |
12//! | [`PointBurstBuilder`](particles::PointBurstBuilder) | Convenience API for radial particle bursts |
13//! | [`CABasicAnimationBuilder`](animation_builder::CABasicAnimationBuilder) | Standalone GPU-accelerated animations |
14//!
15//! # Quick Start
16//!
17//! ```ignore
18//! use core_animation::prelude::*;
19//!
20//! let window = WindowBuilder::new()
21//! .title("Demo")
22//! .size(400.0, 400.0)
23//! .centered()
24//! .background_color(Color::rgb(0.1, 0.1, 0.15))
25//! .build();
26//!
27//! let circle = CAShapeLayerBuilder::new()
28//! .circle(80.0)
29//! .position(CGPoint::new(200.0, 200.0))
30//! .fill_color(Color::CYAN)
31//! .animate("pulse", KeyPath::TransformScale, |a| {
32//! a.values(0.85, 1.15)
33//! .duration(1.seconds())
34//! .easing(Easing::InOut)
35//! .autoreverses()
36//! .repeat(Repeat::Forever)
37//! })
38//! .build();
39//!
40//! window.container().add_sublayer(&circle);
41//! window.show_for(10.seconds());
42//! ```
43//!
44//! # Animations
45//!
46//! All layer builders support `.animate()` for GPU-accelerated animations:
47//!
48//! ```ignore
49//! .animate("name", KeyPath::TransformScale, |a| {
50//! a.values(0.8, 1.2) // from/to values
51//! .duration(500.millis()) // timing
52//! .easing(Easing::InOut) // curve
53//! .autoreverses() // ping-pong
54//! .repeat(Repeat::Forever) // loop
55//! .phase_offset(0.5) // stagger multiple animations
56//! })
57//! ```
58//!
59//! **Animatable properties:** [`TransformScale`](animation_builder::KeyPath::TransformScale),
60//! [`TransformRotation`](animation_builder::KeyPath::TransformRotation),
61//! [`Opacity`](animation_builder::KeyPath::Opacity),
62//! [`ShadowRadius`](animation_builder::KeyPath::ShadowRadius),
63//! [`ShadowOpacity`](animation_builder::KeyPath::ShadowOpacity),
64//! [`Custom`](animation_builder::KeyPath::Custom)
65//!
66//! **Easing curves:** [`Linear`](animation_builder::Easing::Linear),
67//! [`In`](animation_builder::Easing::In),
68//! [`Out`](animation_builder::Easing::Out),
69//! [`InOut`](animation_builder::Easing::InOut)
70//!
71//! # Particle Systems
72//!
73//! ```ignore
74//! use std::f64::consts::PI;
75//!
76//! let emitter = CAEmitterLayerBuilder::new()
77//! .position(320.0, 240.0)
78//! .shape(EmitterShape::Point)
79//! .particle(|p| {
80//! p.birth_rate(100.0)
81//! .lifetime(5.0)
82//! .velocity(80.0)
83//! .emission_range(PI * 2.0)
84//! .color(Color::CYAN)
85//! .image(ParticleImage::soft_glow(64))
86//! })
87//! .build();
88//! ```
89//!
90//! Or use the convenience builder:
91//!
92//! ```ignore
93//! let burst = PointBurstBuilder::new(320.0, 240.0)
94//! .velocity(100.0)
95//! .color(Color::PINK)
96//! .build();
97//! ```
98//!
99//! **Particle images:** [`soft_glow`](particles::ParticleImage::soft_glow),
100//! [`circle`](particles::ParticleImage::circle),
101//! [`star`](particles::ParticleImage::star),
102//! [`spark`](particles::ParticleImage::spark)
103//!
104//! # Examples
105//!
106//! See the [examples](https://github.com/sassman/core-animation-rs/tree/main/examples)
107//! for runnable demos with screenshots.
108//!
109//! ```bash
110//! cargo run --example window_builder
111//! ```
112//!
113//! Use [`prelude`] to import common types.
114
115#![cfg(target_os = "macos")]
116
117pub mod animation_builder;
118mod color;
119mod duration_ext;
120mod layer_builder;
121mod layer_ext;
122pub mod particles;
123mod shape_layer_builder;
124mod text_layer_builder;
125pub mod window;
126
127// Re-export Color type
128pub use color::Color;
129
130// Re-export the main types from objc2-quartz-core
131pub use objc2_quartz_core::{CALayer, CAShapeLayer, CATextLayer, CATransform3D};
132
133// Re-export our builders
134pub use layer_builder::CALayerBuilder;
135pub use shape_layer_builder::CAShapeLayerBuilder;
136pub use text_layer_builder::{CATextLayerBuilder, TextAlign, Truncation};
137
138// Re-export window types
139pub use window::{Screen, Window, WindowBuilder, WindowLevel, WindowStyle};
140
141// Re-export duration extension
142pub use duration_ext::DurationExt;
143
144// Re-export layer extension
145pub use layer_ext::CALayerExt;
146
147// Re-export dependencies for convenience
148pub use objc2_core_foundation;
149pub use objc2_core_graphics;
150pub use objc2_core_text;
151pub use objc2_quartz_core;
152
153/// Prelude module for convenient imports.
154pub mod prelude {
155 // Color type
156 pub use crate::color::Color;
157
158 // Animation builder types
159 pub use crate::animation_builder::{CABasicAnimationBuilder, Easing, KeyPath, Repeat};
160
161 // Builders
162 pub use crate::layer_builder::CALayerBuilder;
163 pub use crate::particles::{
164 CAEmitterCellBuilder, CAEmitterLayerBuilder, EmitterMode, EmitterShape, ParticleImage,
165 PointBurstBuilder, RenderMode,
166 };
167 pub use crate::shape_layer_builder::CAShapeLayerBuilder;
168 pub use crate::text_layer_builder::{CATextLayerBuilder, TextAlign, Truncation};
169 pub use crate::window::{Screen, Window, WindowBuilder, WindowLevel, WindowStyle};
170
171 // Duration extension for ergonomic timing
172 pub use crate::duration_ext::DurationExt;
173
174 // Layer extension for snake_case methods
175 pub use crate::layer_ext::CALayerExt;
176
177 // Core Animation types
178 pub use crate::{CALayer, CAShapeLayer, CATextLayer, CATransform3D};
179 pub use objc2_quartz_core::CABasicAnimation;
180
181 // Core Foundation types (geometry, strings, collections, run loop)
182 pub use objc2_core_foundation::{
183 kCFRunLoopDefaultMode, kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks,
184 CFAttributedString, CFDictionary, CFDictionaryKeyCallBacks, CFDictionaryValueCallBacks,
185 CFIndex, CFRetained, CFRunLoop, CFString, CFStringBuiltInEncodings, CFTimeInterval,
186 CGAffineTransform, CGFloat, CGPoint, CGRect, CGSize,
187 };
188
189 // Core Graphics types (context, colors, paths, transforms, display)
190 pub use objc2_core_graphics::{
191 CGAffineTransformIdentity, CGColor, CGContext, CGDirectDisplayID, CGDisplayBounds,
192 CGMainDisplayID, CGPath,
193 };
194
195 // Core Text types (fonts, lines, string attributes)
196 pub use objc2_core_text::{
197 kCTFontAttributeName, kCTForegroundColorAttributeName, CTFont, CTLine,
198 };
199
200 // AppKit types (NSApplication)
201 pub use objc2_app_kit::NSApplication;
202
203 // Smart pointer for Objective-C objects
204 pub use objc2::rc::Retained;
205}