Documentation
¶
Overview ¶
Package animation interpolates styles and custom values on the host frame clock. Elements use Options and InterpolateStyle for sparse style transitions. For non-style values, pass a Tween or another Animator to Play and use the returned Playback to cancel future ticks.
Index ¶
- func ColorInterpolator(start, end color.Color, progress float64) color.Color
- func EaseInOutCubic(t float64) float64
- func EaseInQuad(t float64) float64
- func EaseOutQuad(t float64) float64
- func FloatInterpolator(start, end float64, progress float64) float64
- func IntInterpolator(start, end int, progress float64) int
- func InterpolateGridTracks(start, end []style.GridTrackSize, progress float64) []style.GridTrackSize
- func InterpolateStyle(start, end style.Style, p float64) style.Style
- func Linear(t float64) float64
- type Animator
- type EasingFunction
- type FrameScheduler
- type Interpolator
- type Options
- type Playback
- type Tween
- func Color(start, end color.Color, duration time.Duration, onUpdate func(color.Color)) *Tween[color.Color]
- func Float(start, end float64, duration time.Duration, onUpdate func(float64)) *Tween[float64]
- func Int(start, end int, duration time.Duration, onUpdate func(int)) *Tween[int]
- func NewTween[T any](start, end T, duration time.Duration, easing EasingFunction, ...) *Tween[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorInterpolator ¶
ColorInterpolator interpolates the alpha-premultiplied RGBA channels of image/color.Color.
func EaseInOutCubic ¶
EaseInOutCubic is a cubic ease-in-ease-out.
func FloatInterpolator ¶
FloatInterpolator interpolates between two float64 values.
func IntInterpolator ¶
IntInterpolator interpolates between two int values.
func InterpolateGridTracks ¶
func InterpolateGridTracks(start, end []style.GridTrackSize, progress float64) []style.GridTrackSize
InterpolateGridTracks interpolates between two slices of GridTrackSize. It iterates through the tracks matching by index. If start and end tracks are of the same Kind, their values are interpolated based on progress. If they are of different kinds, or if the slice lengths differ, it snaps to start (if progress < 0.5) or end (if progress >= 0.5).
func InterpolateStyle ¶
InterpolateStyle blends two sparse styles at normalized progress p in [0, 1]. Numeric dimensions, colors, spacing, flex, and grid tracks interpolate when both sides set compatible values; discrete properties switch at p == 0.5.
Types ¶
type Animator ¶
type Animator interface {
// Tick updates the animation state by the given delta time.
// Returns true if the animation has finished.
Tick(dt time.Duration) bool
}
Animator represents an animation that can be ticked over time.
type EasingFunction ¶
EasingFunction maps progress in the range [0.0, 1.0] to an eased progress value in [0.0, 1.0].
type FrameScheduler ¶
FrameScheduler is the minimal host frame-clock contract (satisfied by terminal.Window).
type Interpolator ¶
Interpolator defines the function signature for interpolating between two values of type T.
type Options ¶
type Options struct {
Duration time.Duration
Easing EasingFunction
OnComplete func()
}
Options configures an element or style animation.
type Playback ¶
type Playback struct {
// contains filtered or unexported fields
}
Playback controls an active animation scheduled on a FrameScheduler.
func Play ¶
func Play(win FrameScheduler, anim Animator) *Playback
Play schedules anim to tick once per frame on win until it finishes or is cancelled.
type Tween ¶
type Tween[T any] struct { Start T End T Duration time.Duration Easing EasingFunction Interp Interpolator[T] OnUpdate func(current T) // contains filtered or unexported fields }
Tween implements Animator, performing interpolation between a start and end value over a duration.
func Color ¶
func Color(start, end color.Color, duration time.Duration, onUpdate func(color.Color)) *Tween[color.Color]
Color creates a Tween interpolating between two color.Color values using EaseOutQuad by default.
func Float ¶
Float creates a Tween interpolating between two float64 values using EaseOutQuad by default.
func NewTween ¶
func NewTween[T any](start, end T, duration time.Duration, easing EasingFunction, interp Interpolator[T], onUpdate func(current T)) *Tween[T]
NewTween creates a new Tween animator.
func (*Tween[T]) Ease ¶
func (t *Tween[T]) Ease(easing EasingFunction) *Tween[T]
Ease sets the easing function for the tween and returns the tween for chaining.
func (*Tween[T]) OnComplete ¶
OnComplete registers a callback invoked once when the tween finishes.