From b4d44573c240d6c1067390d7a23c5b43b2907785 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 10 Dec 2023 14:03:05 -0800 Subject: [PATCH] add StartAnimationPrivate to testDriver; add some comments --- internal/animation/runner.go | 6 ++++-- test/testdriver.go | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/animation/runner.go b/internal/animation/runner.go index b4e5a0ff0d..bad7827aa2 100644 --- a/internal/animation/runner.go +++ b/internal/animation/runner.go @@ -36,7 +36,9 @@ func (r *Runner) runAnimations() { <-draw.C // tick currently running animations - newList := r.animations[:0] // references same underlying backing array + // use technique from https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating + // to filter the still-running animations for the next iteration without allocating a new slice + newList := r.animations[:0] for _, a := range r.animations { if stopped := a.a.State() == fyne.AnimationStateStopped; !stopped && r.tickAnimation(a) { newList = append(newList, a) // still running @@ -56,7 +58,7 @@ func (r *Runner) runAnimations() { done = len(newList) == 0 for i := len(newList); i < len(r.animations); i++ { - r.animations[i] = nil + r.animations[i] = nil // nil out extra slice capacity } r.animations = newList } diff --git a/test/testdriver.go b/test/testdriver.go index 146e44e1ff..273490e168 100644 --- a/test/testdriver.go +++ b/test/testdriver.go @@ -112,6 +112,11 @@ func (d *testDriver) StopAnimation(a *fyne.Animation) { // currently no animations in test app, do nothing } +func (d *testDriver) StartAnimationPrivate(a *fyne.Animation) { + /// currently no animations in test app, we just initialise it and leave + a.Tick(1.0) +} + func (d *testDriver) Quit() { // no-op }