Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up cleanup function queue in fyne_demo #5459

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading