animation/animation.go

Functions Structs

Functions

func AutoReverse

AutoReverse makes the animation reverse direction after each iteration.

func (b *AnimationBuilder) AutoReverse() *AnimationBuilder {
	b.anim.reverse = true
	return b
}

func Build

Build returns the configured Animation without starting it.

 

If From was not called, the from value is set to the signal's current value.

func (b *AnimationBuilder) Build() *Animation {
	a := b.anim
	if !b.fromSet {
		a.from = a.signal.Get()
	}
	return a
}

func Cancel

Cancel stops the animation immediately without calling OnDone.

func (a *Animation) Cancel() {
	a.done = true
}

func Delay

Delay sets a delay before the animation starts.

func (b *AnimationBuilder) Delay(d time.Duration) *AnimationBuilder {
	b.anim.delay = d
	return b
}

func Duration

Duration sets the animation duration. Default is 300ms (M3 Medium2).

func (b *AnimationBuilder) Duration(d time.Duration) *AnimationBuilder {
	b.anim.duration = d
	return b
}

func Ease

Ease sets the easing function. Default is M3Standard.

func (b *AnimationBuilder) Ease(e Easing) *AnimationBuilder {
	b.anim.easing = e
	return b
}

func From

From sets the starting value. If not called, starts from signal.Get().

func (b *AnimationBuilder) From(value float32) *AnimationBuilder {
	b.anim.from = value
	b.fromSet = true
	return b
}

func OnDone

OnDone sets a callback invoked when the animation completes.

Not called if the animation is canceled.

func (b *AnimationBuilder) OnDone(fn func()) *AnimationBuilder {
	b.anim.onDone = fn
	return b
}

func Repeat

Repeat sets the number of additional repetitions.

 

0 means play once (default). Pass -1 for infinite repetition.

func (b *AnimationBuilder) Repeat(count int) *AnimationBuilder {
	b.anim.repeat = count
	return b
}

func Start

Start builds the animation and registers it with the controller.

 

If From was not called, the animation starts from the signal's current value.

If another animation is already running on the same signal, it is auto-canceled.

func (b *AnimationBuilder) Start(ctrl *Controller) *Animation {
	a := b.Build()
	ctrl.add(a)
	return a
}

func To

To creates a new AnimationBuilder that animates the signal to the target value.

 

If From is not called, the animation starts from the signal's current value

at the time Start is called.

func To(signal signalFloat32, target float32) *AnimationBuilder {
	return &AnimationBuilder{
		anim: &Animation{
			signal:		signal,
			to:		target,
			duration:	DurationMedium2,	// 300ms default
			easing:		M3Standard,
		},
	}
}

Structs

type Animation struct

Animation represents a running tween animation that drives a Signal[float32].

 

Animations are created with the [To] builder and started with [AnimationBuilder.Start].

The animation updates its target signal each frame via the Controller's Tick method.

type Animation struct {
	signal	signalFloat32
	from	float32
	to	float32

	duration	time.Duration
	delay		time.Duration
	easing		Easing
	repeat		int	// 0 = once, repeatInfinite = infinite, N = repeat N more times
	reverse		bool	// auto-reverse after each iteration
	onDone		func()

	// internal state
	elapsed	time.Duration
	started	bool
	done	bool
	iter	int
	forward	bool	// current direction (for auto-reverse)
}

type AnimationBuilder struct

AnimationBuilder constructs an Animation using the builder pattern.

 

Example:

 

animation.To(opacity, 1.0).

From(0.0).

Duration(300 * time.Millisecond).

Ease(animation.M3Standard).

Start(ctrl)

type AnimationBuilder struct {
	anim	*Animation
	fromSet	bool
}