Skip to content

Commit

Permalink
Merge pull request #5459 from Jacalz/demo-cleanup-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz authored Jan 25, 2025
2 parents 0be4d85 + 03a7eac commit cc8163c
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cmd/fyne_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func makeNav(setTutorial func(tutorial tutorials.Tutorial), loadPrevious bool) f
OnSelected: func(uid string) {
if t, ok := tutorials.Tutorials[uid]; ok {
for _, f := range tutorials.OnChangeFuncs {
f(uid)
f()
}
tutorials.OnChangeFuncs = nil // Loading a page registers a new cleanup.

Expand Down
7 changes: 1 addition & 6 deletions cmd/fyne_demo/tutorials/advanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ func advancedScreen(win fyne.Window) fyne.CanvasObject {
))

ticker := time.NewTicker(time.Second)

OnChangeFuncs = append(OnChangeFuncs, func(page string) {
if page != "advanced" {
ticker.Stop()
}
})
OnChangeFuncs = append(OnChangeFuncs, ticker.Stop)

go func(canvas fyne.Canvas) {
for range ticker.C {
Expand Down
16 changes: 2 additions & 14 deletions cmd/fyne_demo/tutorials/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ func makeAnimationCanvas() fyne.CanvasObject {
a2.Curve = fyne.AnimationLinear
a2.Start()

OnChangeFuncs = append(OnChangeFuncs, func(page string) {
if page != "animations" {
a.Stop()
a2.Stop()
}
})
OnChangeFuncs = append(OnChangeFuncs, a.Stop, a2.Stop)

running := true
var toggle *widget.Button
Expand All @@ -78,14 +73,7 @@ func makeAnimationCurves() fyne.CanvasObject {
label3, box3, a3 := makeAnimationCurveItem("EaseOut", fyne.AnimationEaseOut, 60+theme.Padding()*2)
label4, box4, a4 := makeAnimationCurveItem("Linear", fyne.AnimationLinear, 90+theme.Padding()*3)

OnChangeFuncs = append(OnChangeFuncs, func(page string) {
if page != "animations" {
a1.Stop()
a2.Stop()
a3.Stop()
a4.Stop()
}
})
OnChangeFuncs = append(OnChangeFuncs, a1.Stop, a2.Stop, a3.Stop, a4.Stop)

start := widget.NewButton("Compare", func() {
a1.Start()
Expand Down
6 changes: 1 addition & 5 deletions cmd/fyne_demo/tutorials/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ func canvasScreen(_ fyne.Window) fyne.CanvasObject {
gradient := canvas.NewHorizontalGradient(color.NRGBA{0x80, 0, 0, 0xff}, color.NRGBA{0, 0x80, 0, 0xff})
ticker := time.NewTicker(time.Second)

OnChangeFuncs = append(OnChangeFuncs, func(page string) {
if page != "canvas" {
ticker.Stop()
}
})
OnChangeFuncs = append(OnChangeFuncs, ticker.Stop)

go func() {
for range ticker.C {
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne_demo/tutorials/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// OnChangeFuncs is a slice of functions that can be registered
// to run when the user switches tutorial.
var OnChangeFuncs []func(string)
var OnChangeFuncs []func()

// Tutorial defines the data structure for a tutorial
type Tutorial struct {
Expand Down
7 changes: 1 addition & 6 deletions cmd/fyne_demo/tutorials/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,7 @@ func makeProgressTab(_ fyne.Window) fyne.CanvasObject {

progressAnimation.Start()

OnChangeFuncs = append(OnChangeFuncs, func(page string) {
if page != "progress" {
progressAnimation.Stop()
infProgress.Stop()
}
})
OnChangeFuncs = append(OnChangeFuncs, progressAnimation.Stop, infProgress.Stop)

return container.NewVBox(
widget.NewLabel("Percent"), progress,
Expand Down

0 comments on commit cc8163c

Please sign in to comment.