Skip to main content

dinamika_core/
lib.rs

1//! `dinamika-core` — a declarative library for building animations on top of
2//! the raster renderer [`dinamika_cpu`].
3//!
4//! It consists of three parts:
5//!
6//! 1. **Shapes** ([`Shape`]) — scene nodes with flex layout (direction, justify,
7//!    align, gap, padding, children) and signal-backed properties (background,
8//!    sizes, corner radius, opacity, rotation). Rectangle, circle, layout
9//!    container and text ([`Shape::text`]) are supported, with CSS-like
10//!    properties (font, font size, color, alignment, line height, letter spacing).
11//! 2. **Signals** ([`Signal`], [`Computed`]) — reactive values in the spirit of
12//!    Motion Canvas: read, written and animated.
13//! 3. **Timeline** ([`Timeline`]) — composition of animations over time: pause
14//!    ([`Timeline::pause`]), parallel ([`Timeline::parallel`]) and sequence
15//!    ([`Timeline::sequence`] / [`Timeline::cascade`]). Shapes are registered
16//!    on the timeline via [`Shape::on`], and properties are animated with the
17//!    same shape setter methods (`x`, `background`, `rotation`, …) — by
18//!    appending `.over(duration, easing)`.
19//!
20//! # Example
21//!
22//! ```
23//! use dinamika_core::*;
24//!
25//! // The timeline is created first (interior mutability — no `mut`).
26//! let tl = Timeline::new(320, 160, Color::from_rgba8(20, 20, 24, 255), 30.0);
27//!
28//! // Scene: a row container with two squares, registered on the timeline.
29//! let a = Shape::rect().background(Color::from_rgba8(229, 192, 123, 255)).size(60.0, 60.0);
30//! let b = Shape::rect().background(Color::from_rgba8(152, 195, 121, 255)).size(60.0, 60.0);
31//! let _row = Shape::rect()
32//!     .at(20.0, 20.0)
33//!     .background(Color::from_rgba8(40, 44, 52, 255))
34//!     .radius(12.0)
35//!     .direction(Direction::Row)
36//!     .gap(20.0)
37//!     .padding(20.0)
38//!     .align(Align::Center)
39//!     .child(a.clone())
40//!     .child(b.clone())
41//!     .on(&tl);
42//!
43//! // Move and recolor in parallel, wait, then a sequence of opacities.
44//! tl.parallel(vec![
45//!     a.rotation(180.0).over(1.0, Easing::CubicInOut),
46//!     b.background(Color::from_rgba8(97, 175, 239, 255)).over(1.0, Easing::Linear),
47//! ]);
48//! tl.pause(0.25);
49//! tl.sequence(vec![
50//!     a.opacity(0.2).over(0.5, Easing::QuadOut),
51//!     b.opacity(0.2).over(0.5, Easing::QuadOut),
52//! ]);
53//!
54//! // A single frame (RGBA, premultiplied alpha).
55//! let frame = tl.frame(0.5);
56//! assert_eq!(frame.width(), 320);
57//! ```
58
59mod easing;
60mod output;
61mod render;
62mod shape;
63mod signal;
64mod timeline;
65
66/// Access to the underlying renderer.
67pub use dinamika_cpu as cpu;
68
69// Frequently used renderer types — for convenience.
70pub use dinamika_cpu::{
71    BlendMode, Color, GradientStop, LinearGradient, Paint, Pixmap, Point, RadialGradient, Rect,
72    Shader, SpreadMode, Transform,
73};
74
75pub use easing::Easing;
76pub use output::scene_output_dir;
77pub use render::render_scene;
78pub use shape::{
79    infinite, line, Align, Direction, HighlightEdit, IntoChildren, Justify, Language, Length,
80    Padding, PaddingTween, Palette, Shape, ShapeKind, TextAlign, TextEdit, TextPos, Tween,
81};
82pub use signal::{Computed, Signal, Tweenable};
83pub use timeline::{cascade, delay, parallel, pause, sequence, Action, Timeline};