ElixirOpentui.Animation.Timeline (ElixirOpentui v0.2.0)

Copy Markdown View Source

Pure functional animation timeline.

A Timeline holds a list of property animations. It advances forward in time via advance/2, producing interpolated values that components read via value/2.

Timelines are plain structs stored in component state, no GenServer needed.

Summary

Functions

Add a property animation to the timeline.

Advance the timeline by dt milliseconds. Returns updated timeline.

Returns true when the timeline has completed (not looping).

Create a new timeline. Options: :duration, :loop, :alternate.

Set the timeline to playing state. A completed timeline starts over.

Get the current interpolated value for a property.

Types

item()

@type item() :: %{
  property: atom(),
  from: number(),
  to: number(),
  easing: atom(),
  duration: non_neg_integer(),
  delay: non_neg_integer()
}

state()

@type state() :: :idle | :playing | :complete

t()

@type t() :: %ElixirOpentui.Animation.Timeline{
  alternate: boolean(),
  duration: non_neg_integer(),
  elapsed: float(),
  items: [item()],
  loop: boolean() | pos_integer(),
  loop_count: non_neg_integer(),
  state: state(),
  values: %{optional(atom()) => number()}
}

Functions

add(tl, property, opts \\ [])

@spec add(t(), atom(), keyword()) :: t()

Add a property animation to the timeline.

advance(tl, dt)

@spec advance(t(), number()) :: t()

Advance the timeline by dt milliseconds. Returns updated timeline.

finished?(arg1)

@spec finished?(t()) :: boolean()

Returns true when the timeline has completed (not looping).

new(opts \\ [])

@spec new(keyword()) :: t()

Create a new timeline. Options: :duration, :loop, :alternate.

play(tl)

@spec play(t()) :: t()

Set the timeline to playing state. A completed timeline starts over.

value(timeline, property)

@spec value(t(), atom()) :: number()

Get the current interpolated value for a property.