From e19eededfdc41a12efd7c1222c16ba9488b8ed99 Mon Sep 17 00:00:00 2001 From: Jacalz Date: Tue, 21 May 2024 21:29:35 +0200 Subject: [PATCH] Rework activity widget to not talk directly with renderer --- widget/activity.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/widget/activity.go b/widget/activity.go index 1bfa3eb584..5e6b88d8b6 100644 --- a/widget/activity.go +++ b/widget/activity.go @@ -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" ) @@ -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 @@ -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 { @@ -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() } @@ -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() } @@ -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() }