Skip to content

Commit

Permalink
add StartAnimationPrivate to testDriver; add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Dec 10, 2023
1 parent 55eb2d8 commit b4d4457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/animation/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions test/testdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b4d4457

Please sign in to comment.