app: add basic tabs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-05-23 01:23:03 +02:00
parent e669770871
commit 8142ed8cfe
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 75 additions and 1 deletions

@ -23,7 +23,7 @@ func RunApp() {
w := a.NewWindow(cmd.GetAppName()) w := a.NewWindow(cmd.GetAppName())
centered := container.New(layout.NewHBoxLayout(), layout.NewSpacer(), makeGreeting(), layout.NewSpacer()) centered := container.New(layout.NewHBoxLayout(), layout.NewSpacer(), makeGreeting(), layout.NewSpacer())
w.SetContent(container.New(layout.NewVBoxLayout(), makeToolbar(), centered)) w.SetContent(container.New(layout.NewVBoxLayout(), makeToolbar(), centered, makeTabs()))
w.Resize(fyne.NewSize(400, 400)) w.Resize(fyne.NewSize(400, 400))
w.ShowAndRun() w.ShowAndRun()
@ -51,3 +51,11 @@ func makeToolbar() *widget.Toolbar {
) )
return toolbar return toolbar
} }
func makeTabs() *container.AppTabs {
tabs := container.NewAppTabs(
container.NewTabItem("xkcd comic", widget.NewLabel("Latest comic...")),
container.NewTabItem("what if?", widget.NewLabel("serious answers to absurd questions and absurd advice for common concerns from xkcd's Randall Munroe")),
)
return tabs
}

@ -26,3 +26,69 @@ func TestToolbar(t *testing.T) {
t.Errorf("Incorrect number of toolbar items, want: %d, got: %d", wantItems, len(gotToolbar.Items)) t.Errorf("Incorrect number of toolbar items, want: %d, got: %d", wantItems, len(gotToolbar.Items))
} }
} }
func TestTabs(t *testing.T) {
// wantTabsNum := 2
// gotTabs := makeTabs()
//
// if len(gotTabs.Items) != wantTabsNum {
// t.Errorf("Incorrect number of app tabs, want: %d, got: %d", wantTabsNum, len(gotTabs.Items))
// }
//
// tab0 := 0
// gotTabs.SelectIndex(tab0)
//
// if gotTabs.SelectedIndex() != tab0 {
// t.Errorf("Failed to select tab %d", tab0)
// }
//
// tab0Text := "xkcd comic"
// if gotTabs.CurrentTab().Text != tab0Text {
// t.Errorf("Tab0 text is not %q", tab0Text)
// }
//
// hitting the following test failure with the above:
//
/*
--- FAIL: TestTabs (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x68 pc=0x55e29ca4fbb1]
goroutine 35 [running]:
testing.tRunner.func1.2({0x55e29cda1240, 0x55e29d06a1e0})
testing/testing.go:1389 +0x24e
testing.tRunner.func1()
testing/testing.go:1392 +0x39f
panic({0x55e29cda1240, 0x55e29d06a1e0})
runtime/panic.go:838 +0x207
fyne.io/fyne/v2/theme.(*builtinTheme).Color(0x60?, {0x55e29cc346ea?, 0xc000120d00?}, 0x55e29ca50699?)
fyne.io/fyne/v2@v2.1.4/theme/theme.go:322 +0x71
fyne.io/fyne/v2/theme.safeColorLookup({0x55e29cc346ea, 0x7}, 0x1?)
fyne.io/fyne/v2@v2.1.4/theme/theme.go:644 +0x47
fyne.io/fyne/v2/theme.PrimaryColor()
fyne.io/fyne/v2@v2.1.4/theme/theme.go:449 +0x2d
fyne.io/fyne/v2/container.(*AppTabs).CreateRenderer(0xc00014a000)
fyne.io/fyne/v2@v2.1.4/container/apptabs.go:55 +0x85
fyne.io/fyne/v2/internal/cache.Renderer({0x55e29ce17918, 0xc00014a000})
fyne.io/fyne/v2@v2.1.4/internal/cache/widget.go:33 +0x162
fyne.io/fyne/v2/widget.(*BaseWidget).Refresh(0x55e29ce171f8?)
fyne.io/fyne/v2@v2.1.4/widget/widget.go:137 +0x25
fyne.io/fyne/v2/container.(*AppTabs).SetItems(0xc00014a000, {0xc000130080?, 0xc00014a000?, 0x55e29cd837e0?})
fyne.io/fyne/v2@v2.1.4/container/apptabs.go:182 +0x45
fyne.io/fyne/v2/container.NewAppTabs({0xc000130080, 0x2, 0x2})
fyne.io/fyne/v2@v2.1.4/container/apptabs.go:42 +0x5e
git.dotya.ml/wanderer/go-xkcdreader/xkcdreader.makeTabs()
git.dotya.ml/wanderer/go-xkcdreader/xkcdreader/app.go:57 +0x145
git.dotya.ml/wanderer/go-xkcdreader/xkcdreader.TestTabs(0xc000102820)
git.dotya.ml/wanderer/go-xkcdreader/xkcdreader/app_test.go:32 +0x25
testing.tRunner(0xc000102820, 0x55e29ce0f890)
testing/testing.go:1439 +0x102
created by testing.(*T).Run
testing/testing.go:1486 +0x35f
FAIL git.dotya.ml/wanderer/go-xkcdreader/xkcdreader 0.011s
FAIL
*/
}