Skip to main content

Crate dinamika_core

Crate dinamika_core 

Source
Expand description

dinamika-core — a declarative library for building animations on top of the raster renderer dinamika_cpu.

It consists of three parts:

  1. Shapes (Shape) — scene nodes with flex layout (direction, justify, align, gap, padding, children) and signal-backed properties (background, sizes, corner radius, opacity, rotation). Rectangle, circle, layout container and text (Shape::text) are supported, with CSS-like properties (font, font size, color, alignment, line height, letter spacing).
  2. Signals (Signal, Computed) — reactive values in the spirit of Motion Canvas: read, written and animated.
  3. Timeline (Timeline) — composition of animations over time: pause (Timeline::pause), parallel (Timeline::parallel) and sequence (Timeline::sequence / Timeline::cascade). Shapes are registered on the timeline via Shape::on, and properties are animated with the same shape setter methods (x, background, rotation, …) — by appending .over(duration, easing).

§Example

use dinamika_core::*;

// The timeline is created first (interior mutability — no `mut`).
let tl = Timeline::new(320, 160, Color::from_rgba8(20, 20, 24, 255), 30.0);

// Scene: a row container with two squares, registered on the timeline.
let a = Shape::rect().background(Color::from_rgba8(229, 192, 123, 255)).size(60.0, 60.0);
let b = Shape::rect().background(Color::from_rgba8(152, 195, 121, 255)).size(60.0, 60.0);
let _row = Shape::rect()
    .at(20.0, 20.0)
    .background(Color::from_rgba8(40, 44, 52, 255))
    .radius(12.0)
    .direction(Direction::Row)
    .gap(20.0)
    .padding(20.0)
    .align(Align::Center)
    .child(a.clone())
    .child(b.clone())
    .on(&tl);

// Move and recolor in parallel, wait, then a sequence of opacities.
tl.parallel(vec![
    a.rotation(180.0).over(1.0, Easing::CubicInOut),
    b.background(Color::from_rgba8(97, 175, 239, 255)).over(1.0, Easing::Linear),
]);
tl.pause(0.25);
tl.sequence(vec![
    a.opacity(0.2).over(0.5, Easing::QuadOut),
    b.opacity(0.2).over(0.5, Easing::QuadOut),
]);

// A single frame (RGBA, premultiplied alpha).
let frame = tl.frame(0.5);
assert_eq!(frame.width(), 320);

Re-exports§

pub use dinamika_cpu as cpu;

Macros§

render
Renders the whole timeline animation into the outputs/<scene> directory next to the .rs file where the macro is called; returns a std::io::Result carrying only success/failure. The number of saved frames is not returned — if you need it, call Timeline::render directly.
scene_dir
Default output directory for a scene — outputs/<scene> next to the .rs file where the macro is called.

Structs§

Action
The unit of timeline composition: a tween, pause, parallel or sequence.
Color
A color in floating-point RGBA format in the range 0.0..=1.0, non-premultiplied alpha.
Computed
A derived (computed) signal — read-only.
GradientStop
A gradient stop.
HighlightEdit
A handle of range highlighting, returned by highlight and clear_highlight.
LinearGradient
A linear gradient along the segment startend.
Padding
The shape’s inner padding by side.
PaddingTween
A handle of the padding property — like Tween, but animates all four padding sides at once. over builds a parallel tween.
Paint
A fill description: the color source, blend mode and anti-aliasing.
Palette
A highlight palette: “token category → color”, assembled manually.
Pixmap
Bitmap: width × height RGBA pixels, premultiplied alpha.
Point
A point (or vector) in the plane.
RadialGradient
A radial gradient around a center.
Rect
A rectangle defined by its bounds in floating-point coordinates.
Shape
A scene node. This is a cheap shared handle (Rc): a clone points to the same shape, so it can be held both in the scene tree and in the timeline.
Signal
A reactive value, shared by reference.
TextEdit
A handle of a text edit, returned by the text shape’s editor methods (content, append, prepend, insert, rewrite).
Timeline
An animation timeline: a top-level sequence of actions plus references to the shapes to draw.
Transform
A 2×3 affine transformation.
Tween
A handle of an animatable property, returned by its setter method.

Enums§

Align
Alignment along the cross axis (analogous to align-items).
BlendMode
Blend mode of the source and the background.
Direction
The children’s layout axis (analogous to flex-direction).
Easing
Animation easing curve.
Justify
Distribution along the main axis (analogous to justify-content).
Language
The code shape’s highlight language. Resolves to a Sublime Text grammar from the built-in syntect set; an unknown grammar (or PlainText) means “no parsing” — all the code is colored with the palette’s base color.
Length
A length along one axis: absolute in pixels, or a fraction of the parent’s content area in percent. Passed to width and height.
Shader
A color source.
ShapeKind
Shape kind.
SpreadMode
How coordinates outside 0..=1 are handled for a gradient.
TextAlign
Horizontal alignment of lines within a text block (analogous to CSS text-align).
TextPos
A position in the text for the bounds of a rewrite range.

Traits§

IntoChildren
Conversion of a Shape::children argument into a list of child shapes.
Tweenable
A type whose values can be linearly interpolated.

Functions§

cascade
A cascade: sequential execution of actions with a gap-second pause between neighbors. Put inside the animations that should follow each other in a “wave”.
delay
An action that starts after seconds seconds.
infinite
The position of the end of the text for the to bound in rewrite.
line
The position of the start of line n (0-based) for rewrite.
parallel
Simultaneous execution of all the actions. The duration is the maximum of the nested ones.
pause
A pause of the given duration (in seconds).
render_scene
Draws a scene of root shapes over the background.
scene_output_dir
Default output directory for a scene: <source-dir>/outputs/<scene>.
sequence
Sequential execution one after another (with no gaps).