Skip to content

Commit

Permalink
Rework activity widget to not talk directly with renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed May 21, 2024
1 parent a287ba6 commit e19eede
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions widget/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/internal/cache"
"fyne.io/fyne/v2/theme"
)

Expand Down Expand Up @@ -43,9 +42,8 @@ func (a *Activity) Start() {
return // already started
}

if r, ok := cache.Renderer(a.super()).(*activityRenderer); ok {
r.start()
}

a.Refresh()
}

// Stop the activity indicator animation
Expand All @@ -54,9 +52,7 @@ func (a *Activity) Stop() {
return // already stopped
}

if r, ok := cache.Renderer(a.super()).(*activityRenderer); ok {
r.stop()
}
a.Refresh()
}

func (a *Activity) CreateRenderer() fyne.WidgetRenderer {
Expand Down Expand Up @@ -89,9 +85,11 @@ type activityRenderer struct {
bound fyne.Size
maxCol color.NRGBA
maxRad float32
wasStarted bool
}

func (a *activityRenderer) Destroy() {
a.parent.started.Store(false)
a.stop()
}

Expand All @@ -109,6 +107,17 @@ func (a *activityRenderer) Objects() []fyne.CanvasObject {
}

func (a *activityRenderer) Refresh() {
started := a.parent.started.Load()
if started {
if !a.wasStarted {
a.start()
}
return
} else if a.wasStarted {
a.stop()
return
}

a.updateColor()
}

Expand Down Expand Up @@ -152,10 +161,12 @@ func (a *activityRenderer) scaleDot(dot *canvas.Circle, off float32) {
}

func (a *activityRenderer) start() {
a.wasStarted = true
a.anim.Start()
}

func (a *activityRenderer) stop() {
a.wasStarted = false
a.anim.Stop()
}

Expand Down

0 comments on commit e19eede

Please sign in to comment.