Skip to main content

Module animation

Module animation 

Source
Expand description

One-cell animations: an ordered list of frames, each with a glyph per glyph mode and an optional colour, played at a theme or literal frame time.

Every spinner style, the spinner’s finish and anything an application defines are the same CellAnimation data. They are written in icon set and theme files, so a theme or an application replaces a built-in animation the way it replaces an icon:

[animations.spinner-arc]
frame = "spinner"          # a [motion] key, or a duration such as "80ms"
playback = "loop"          # loop | once | bounce
colors = "step"            # step | blend
rest = 1                   # the frame shown with reduced motion, counted from 1
frames = [
  { unicode = "◜", ascii = "-" },
  { nerd = "\uEE07", unicode = "◠", ascii = "\\", color = "mix($accent, $fg, 40%)" },
  { ascii = "|", color = "#38BDF8", duration = "120ms" },
]
  • Glyphs. ascii is required; a missing unicode falls back to ascii and a missing nerd to unicode. Every glyph is exactly one cell, and none may be a bracket.
  • Colours are theme colour expressions: $token, #RRGGBB, mix(a, b, N%) and pulse(a, b). $fg is the colour of the widget drawing the animation. A frame without a colour takes the widget’s colour.
  • Colour modes. step shows each frame in its own colour; blend moves the colour smoothly towards the next frame’s colour while a frame is shown.
  • Playback. loop repeats, once plays once and rests on the last frame, bounce plays forward and back.
  • Reduced motion shows the rest frame (the first, or the last for once) standing still; a pulse() then shows its second colour.

Draw a named animation with PaintCx::animation, or sample a CellAnimation directly with CellAnimation::sample.

Structs§

AnimatedCell
One cell of a playing animation, as PaintCx::animation returns it.
AnimationFrame
One frame: its glyphs, and optionally its own colour and duration.
AnimationName
The name of a registered animation, such as "spinner-arc". Widgets that play animations take anything that converts into one: a string or a SpinnerStyle.
CellAnimation
A one-cell animation. See the module documentation for the file format.
CellColor
The colour of a frame: a theme colour expression, resolved against the theme drawing it.
CellFrame
What an animation shows at one moment.

Enums§

ColorMode
How colours move between frames.
FrameTime
How long a frame is shown: a [motion] key of the theme, or a fixed duration.
Playback
How the frames follow one another.

Constants§

MAX_FRAMES
The most frames one animation may have; a longer list is an error in a file.

Functions§

check_glyph
Checks that glyph can be the mode glyph of a frame: one grapheme, exactly one cell wide, not a bracket, and printable ASCII in GlyphMode::Ascii.
is_valid_name
Whether name can name an animation: lowercase letters, digits and -, like colour tokens.
parse_animations
Reads a file holding only [animations.<name>] tables, such as the animations an application or a tool saved. Returns the usable animations in file order and every problem found; a broken animation is skipped, a file that is not TOML yields no animations.