Skip to content

Commit 492949e

Browse files
committed
Toolbar with restart
1 parent 53a22ab commit 492949e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

main.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,38 @@ package main
44
import (
55
"fyne.io/fyne/v2"
66
"fyne.io/fyne/v2/app"
7+
"fyne.io/fyne/v2/container"
8+
"fyne.io/fyne/v2/dialog"
9+
"fyne.io/fyne/v2/theme"
10+
"fyne.io/fyne/v2/widget"
711
)
812

913
// show creates a new game and loads a table rendered in a new window.
1014
func show(app fyne.App) {
1115
game := NewGame()
16+
table := NewTable(game)
1217

1318
w := app.NewWindow("Solitaire")
14-
w.SetPadded(false)
15-
w.SetContent(NewTable(game))
19+
bar := widget.NewToolbar(
20+
widget.NewToolbarAction(theme.ViewRefreshIcon(), func() {
21+
checkRestart(table, w)
22+
}))
23+
w.SetContent(container.NewBorder(bar, nil, nil, nil, table))
1624
w.Resize(fyne.NewSize(minWidth, minHeight))
1725

1826
w.Show()
1927
}
2028

29+
func checkRestart(t *Table, w fyne.Window) {
30+
dialog.ShowConfirm("New Game", "Start a new game?", func(ok bool) {
31+
if !ok {
32+
return
33+
}
34+
35+
t.Restart()
36+
}, w)
37+
}
38+
2139
func main() {
2240
a := app.New()
2341
a.SetIcon(resourceIconPng)

table.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ func (t *Table) checkStackTapped(render *stackRender, stack *Stack, pos fyne.Pos
9292
})
9393
}
9494

95+
func (t *Table) Restart() {
96+
t.game = NewGame()
97+
test.WidgetRenderer(t).(*tableRender).game = t.game
98+
t.Refresh()
99+
}
100+
95101
// Tapped is called when the user taps the table widget
96102
func (t *Table) Tapped(event *fyne.PointEvent) {
97103
render := test.WidgetRenderer(t).(*tableRender)

0 commit comments

Comments
 (0)