From e669770871c5559e756915baa0e5c90c0a9bbdc2 Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 23 May 2022 00:49:04 +0200 Subject: [PATCH] app: create a toolbar --- xkcdreader/app.go | 21 ++++++++++++++++++++- xkcdreader/app_test.go | 9 +++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/xkcdreader/app.go b/xkcdreader/app.go index ac308b2..530320b 100644 --- a/xkcdreader/app.go +++ b/xkcdreader/app.go @@ -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 +} diff --git a/xkcdreader/app_test.go b/xkcdreader/app_test.go index 9ea109b..8cd881e 100644 --- a/xkcdreader/app_test.go +++ b/xkcdreader/app_test.go @@ -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)) + } +}