animation/controller.go
Functions
func Cancel
func (c *Controller) Cancel(signal signalFloat32) {
delete(c.active, any(signal))
}
func CancelAll
CancelAll stops all animations immediately without calling OnDone callbacks.
func (c *Controller) CancelAll() {
for key := range c.active {
delete(c.active, key)
}
c.compositions = c.compositions[:0]
}
func HasActive
HasActive reports whether any animations are running.
func (c *Controller) HasActive() bool {
return len(c.active) > 0 || len(c.compositions) > 0
}
func NewController
NewController creates a new animation controller.
func NewController() *Controller {
return &Controller{
active: make(map[any]animatable),
}
}
func Tick
Tick advances all active animations by dt.
Returns true if any animations are still running. The caller should request
a new frame when this returns true:
active := ctrl.Tick(dt)
if active { window.RequestRedraw() }
func (c *Controller) Tick(dt time.Duration) bool {
// Tick signal-keyed animations.
for key, anim := range c.active {
if anim.step(dt) {
delete(c.active, key)
}
}
// Tick compositions.
n := 0
for _, comp := range c.compositions {
if !comp.step(dt) {
c.compositions[n] = comp
n++
}
}
// Clear references to allow GC.
for i := n; i < len(c.compositions); i++ {
c.compositions[i] = nil
}
c.compositions = c.compositions[:n]
return len(c.active) > 0 || len(c.compositions) > 0
}
Structs
type Controller struct
Controller manages active animations and provides the Tick entry point.
The Controller owns a map of signal -> active animation for auto-cancel.
When a new animation targets a signal that already has an active animation,
the old animation is automatically canceled.
Controller is designed to be owned by a window and accessed via widget.Context.
It is NOT thread-safe; all calls must happen on the UI thread.
type Controller struct {
// active animations indexed by signal identity for O(1) auto-cancel lookup.
active map[any]animatable
// compositions (Sequence/Parallel) that don't target a single signal.
compositions []animatable
}
Cancel stops the animation targeting the given signal.
The signal parameter should be the same signal passed to To() or SpringTo().