app: create a toolbar
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-05-23 00:49:04 +02:00
parent 2e13ad9faf
commit e669770871
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 29 additions and 1 deletions

@ -4,10 +4,13 @@
package xkcdreader
import (
"log"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"git.dotya.ml/wanderer/go-xkcdreader/cmd"
)
@ -20,7 +23,7 @@ func RunApp() {
w := a.NewWindow(cmd.GetAppName())
centered := container.New(layout.NewHBoxLayout(), layout.NewSpacer(), makeGreeting(), layout.NewSpacer())
w.SetContent(container.New(layout.NewVBoxLayout(), centered))
w.SetContent(container.New(layout.NewVBoxLayout(), makeToolbar(), centered))
w.Resize(fyne.NewSize(400, 400))
w.ShowAndRun()
@ -32,3 +35,19 @@ func makeGreeting() *widget.Label {
w.TextStyle.Monospace = true
return w
}
func makeToolbar() *widget.Toolbar {
toolbar := widget.NewToolbar(
widget.NewToolbarAction(theme.SearchIcon(), func() {
log.Println("Search")
}),
widget.NewToolbarSpacer(),
widget.NewToolbarAction(theme.HelpIcon(), func() {
log.Println("Display help")
}),
widget.NewToolbarAction(theme.SettingsIcon(), func() {
log.Println("Display settings")
}),
)
return toolbar
}

@ -17,3 +17,12 @@ func TestGreetingText(t *testing.T) {
t.Errorf("Incorrect initial greeting, want: %q, got: %q", want, got.Text)
}
}
func TestToolbar(t *testing.T) {
wantItems := 4
gotToolbar := makeToolbar()
if len(gotToolbar.Items) != wantItems {
t.Errorf("Incorrect number of toolbar items, want: %d, got: %d", wantItems, len(gotToolbar.Items))
}
}