animation.go 659 B

123456789101112131415161718192021222324252627282930313233
  1. package animation
  2. import (
  3. "sync/atomic"
  4. "time"
  5. "fyne.io/fyne/v2"
  6. )
  7. type anim struct {
  8. a *fyne.Animation
  9. end time.Time
  10. repeatsLeft int
  11. reverse bool
  12. start time.Time
  13. total int64
  14. stopped uint32 // atomic, 0 == false 1 == true
  15. }
  16. func newAnim(a *fyne.Animation) *anim {
  17. animate := &anim{a: a, start: time.Now(), end: time.Now().Add(a.Duration)}
  18. animate.total = animate.end.Sub(animate.start).Milliseconds()
  19. animate.repeatsLeft = a.RepeatCount
  20. return animate
  21. }
  22. func (a *anim) setStopped() {
  23. atomic.StoreUint32(&a.stopped, 1)
  24. }
  25. func (a *anim) isStopped() bool {
  26. return atomic.LoadUint32(&a.stopped) == 1
  27. }