Skip to main content

animation

Package animation provides animation primitives for the Drift framework.

Variables

Ease is a standard cubic bezier curve for general-purpose easing.

var Ease = CubicBezier(0.25, 0.1, 0.25, 1.0)

EaseIn is a cubic bezier curve that starts slowly and accelerates.

var EaseIn = CubicBezier(0.4, 0.0, 1.0, 1.0)

EaseInOut is a cubic bezier curve that starts and ends slowly.

var EaseInOut = CubicBezier(0.4, 0.0, 0.2, 1.0)

EaseOut is a cubic bezier curve that starts quickly and decelerates.

var EaseOut = CubicBezier(0.0, 0.0, 0.2, 1.0)

IOSNavigationCurve approximates iOS navigation easing.

var IOSNavigationCurve = CubicBezier(0.32, 0.72, 0.0, 1.0)

func CubicBezier

func CubicBezier(x1, y1, x2, y2 float64) func(float64) float64

CubicBezier returns a cubic-bezier easing function.

func HasActiveTickers

func HasActiveTickers() bool

HasActiveTickers returns true if any tickers are active.

func LerpAlignment

func LerpAlignment(a, b layout.Alignment, t float64) layout.Alignment

LerpAlignment linearly interpolates between two Alignment values.

func LerpColor

func LerpColor(a, b rendering.Color, t float64) rendering.Color

LerpColor linearly interpolates between two Color values.

func LerpEdgeInsets

func LerpEdgeInsets(a, b layout.EdgeInsets, t float64) layout.EdgeInsets

LerpEdgeInsets linearly interpolates between two EdgeInsets values.

func LerpFloat64

func LerpFloat64(a, b float64, t float64) float64

LerpFloat64 linearly interpolates between two float64 values.

func LerpOffset

func LerpOffset(a, b rendering.Offset, t float64) rendering.Offset

LerpOffset linearly interpolates between two Offset values.

func LerpRadius

func LerpRadius(a, b rendering.Radius, t float64) rendering.Radius

LerpRadius linearly interpolates between two Radius values.

func LinearCurve

func LinearCurve(t float64) float64

LinearCurve returns linear progress.

func StepTickers

func StepTickers()

StepTickers advances all active tickers. This should be called once per frame from the engine.

type AnimationController

AnimationController drives an animation over time.

type AnimationController struct {
// Value is the current animation value, ranging from 0.0 to 1.0.
Value float64

// Duration is the length of the animation.
Duration time.Duration

// Curve transforms linear progress (optional).
Curve func(float64) float64

// LowerBound is the minimum value (default 0.0).
LowerBound float64

// UpperBound is the maximum value (default 1.0).
UpperBound float64
// contains filtered or unexported fields
}

func NewAnimationController

func NewAnimationController(duration time.Duration) *AnimationController

NewAnimationController creates an animation controller with the given duration.

func (*AnimationController) AddListener

func (c *AnimationController) AddListener(fn func()) func()

AddListener adds a callback that fires whenever the value changes. Returns an unsubscribe function.

func (*AnimationController) AddStatusListener

func (c *AnimationController) AddStatusListener(fn func(AnimationStatus)) func()

AddStatusListener adds a callback that fires whenever the status changes. Returns an unsubscribe function.

func (*AnimationController) AnimateTo

func (c *AnimationController) AnimateTo(target float64)

AnimateTo animates to a specific target value.

func (*AnimationController) Dispose

func (c *AnimationController) Dispose()

Dispose cleans up resources used by the controller.

func (*AnimationController) Forward

func (c *AnimationController) Forward()

Forward animates from the current value to the upper bound (1.0).

func (*AnimationController) IsAnimating

func (c *AnimationController) IsAnimating() bool

IsAnimating returns true if the animation is currently running.

func (*AnimationController) IsCompleted

func (c *AnimationController) IsCompleted() bool

IsCompleted returns true if the animation finished at the upper bound.

func (*AnimationController) IsDismissed

func (c *AnimationController) IsDismissed() bool

IsDismissed returns true if the animation is at the lower bound.

func (*AnimationController) Reset

func (c *AnimationController) Reset()

Reset immediately sets the value to the lower bound.

func (*AnimationController) Reverse

func (c *AnimationController) Reverse()

Reverse animates from the current value to the lower bound (0.0).

func (*AnimationController) Status

func (c *AnimationController) Status() AnimationStatus

Status returns the current animation status.

func (*AnimationController) Stop

func (c *AnimationController) Stop()

Stop stops the animation at the current value.

type AnimationStatus

AnimationStatus represents the current state of an animation.

type AnimationStatus int
const (
// AnimationDismissed means the animation is at 0.0.
AnimationDismissed AnimationStatus = iota
// AnimationForward means the animation is playing toward 1.0.
AnimationForward
// AnimationReverse means the animation is playing toward 0.0.
AnimationReverse
// AnimationCompleted means the animation is at 1.0.
AnimationCompleted
)

type SpringDescription

SpringDescription describes the physical properties of a spring.

type SpringDescription struct {
// Stiffness controls how quickly the spring returns to rest (higher = faster).
Stiffness float64
// Damping controls energy dissipation (higher = less oscillation).
// DampingRatio of 1.0 is critically damped (no overshoot).
// DampingRatio < 1.0 is underdamped (some bounce).
// DampingRatio > 1.0 is overdamped (slow return).
DampingRatio float64
}

func BouncySpring

func BouncySpring() SpringDescription

BouncySpring returns slightly underdamped spring for a subtle bounce effect.

func IOSSpring

func IOSSpring() SpringDescription

IOSSpring returns spring parameters that approximate iOS scroll bounce.

type SpringSimulation

SpringSimulation simulates a damped spring for physics-based animations.

type SpringSimulation struct {
// contains filtered or unexported fields
}

func NewSpringSimulation

func NewSpringSimulation(spring SpringDescription, position, velocity, target float64) *SpringSimulation

NewSpringSimulation creates a spring simulation from current position/velocity to target.

func (*SpringSimulation) IsDone

func (s *SpringSimulation) IsDone() bool

IsDone returns true if the simulation has settled at the target.

func (*SpringSimulation) Position

func (s *SpringSimulation) Position() float64

Position returns the current position.

func (*SpringSimulation) Step

func (s *SpringSimulation) Step(dt float64) bool

Step advances the simulation by dt seconds. Returns true if the simulation has settled (is done).

func (*SpringSimulation) Target

func (s *SpringSimulation) Target() float64

Target returns the target position.

func (*SpringSimulation) Velocity

func (s *SpringSimulation) Velocity() float64

Velocity returns the current velocity.

type Ticker

Ticker calls a callback on each frame.

type Ticker struct {
// contains filtered or unexported fields
}

func NewTicker

func NewTicker(callback func(elapsed time.Duration)) *Ticker

NewTicker creates a new ticker with the given callback.

func (*Ticker) Elapsed

func (t *Ticker) Elapsed() time.Duration

Elapsed returns the time since the ticker started.

func (*Ticker) IsActive

func (t *Ticker) IsActive() bool

IsActive returns whether the ticker is currently running.

func (*Ticker) Start

func (t *Ticker) Start()

Start activates the ticker.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop deactivates the ticker.

type TickerProvider

TickerProvider creates tickers.

type TickerProvider interface {
CreateTicker(callback func(time.Duration)) *Ticker
}

type Tween

Tween interpolates between begin and end values.

type Tween[T any] struct {
// Begin is the starting value of the interpolation.
Begin T
// End is the ending value of the interpolation.
End T
// Lerp is the interpolation function. It receives the begin value, end value,
// and a progress value t in the range [0, 1].
Lerp func(a, b T, t float64) T
}

func TweenAlignment

func TweenAlignment(begin, end layout.Alignment) *Tween[layout.Alignment]

TweenAlignment creates a tween for Alignment values.

func TweenColor

func TweenColor(begin, end rendering.Color) *Tween[rendering.Color]

TweenColor creates a tween for Color values.

func TweenEdgeInsets

func TweenEdgeInsets(begin, end layout.EdgeInsets) *Tween[layout.EdgeInsets]

TweenEdgeInsets creates a tween for EdgeInsets values.

func TweenFloat64

func TweenFloat64(begin, end float64) *Tween[float64]

TweenFloat64 creates a tween for float64 values.

func TweenOffset

func TweenOffset(begin, end rendering.Offset) *Tween[rendering.Offset]

TweenOffset creates a tween for Offset values.

func TweenRadius

func TweenRadius(begin, end rendering.Radius) *Tween[rendering.Radius]

TweenRadius creates a tween for Radius values.

func (*Tween[T]) Evaluate

func (tw *Tween[T]) Evaluate(t float64) T

Evaluate returns the interpolated value at t (0.0 to 1.0).

func (*Tween[T]) Transform

func (tw *Tween[T]) Transform(controller *AnimationController) T

Transform returns the interpolated value using the controller's current value.

Generated by gomarkdoc