go-xkcdreader/xkcdreader/app.go
surtur 53be19912a
All checks were successful
continuous-integration/drone/push Build is passing
app: add stuff to 'browse' tab
2022-05-25 23:33:27 +02:00

124 lines
2.9 KiB
Go

// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package xkcdreader
import (
"fmt"
"log"
"time"
"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"
)
const appGreeting = "welcome to go-xkcdreader"
var a fyne.App
// RunApp performs sets up and runs the main application
func RunApp() {
// initialize the fyne application
newApp()
goxkcdreader := getApp()
w := goxkcdreader.NewWindow(cmd.GetAppName())
centered := container.New(
layout.NewHBoxLayout(),
layout.NewSpacer(),
makeGreeting(),
layout.NewSpacer(),
)
w.SetContent(container.New(
layout.NewVBoxLayout(),
makeToolbar(),
centered,
makeTabs(),
))
w.Resize(fyne.NewSize(400, 400))
w.ShowAndRun()
}
func newApp() {
a = app.New()
log.Println("Created a new fyne application")
}
func getApp() fyne.App {
return a
}
// makeGreeting creates a greeting label
func makeGreeting() *widget.Label {
w := widget.NewLabel(appGreeting)
w.TextStyle.Monospace = true
return w
}
func makeToolbar() *widget.Toolbar {
toolbar := widget.NewToolbar(
widget.NewToolbarSpacer(),
widget.NewToolbarAction(theme.HelpIcon(), func() {
log.Println("Display help")
}),
widget.NewToolbarAction(theme.SettingsIcon(), func() {
log.Println("Display settings")
}),
widget.NewToolbarAction(theme.InfoIcon(), aboutWindow),
)
return toolbar
}
func makeTabs() *container.AppTabs {
tabs := container.NewAppTabs(
container.NewTabItem("browse", makeBrowseUI()),
container.NewTabItem("what if?", widget.NewLabel("serious answers to absurd questions and absurd advice for common concerns from xkcd's Randall Munroe")),
container.NewTabItemWithIcon("search", theme.SearchIcon(), makeSearchTab()),
)
return tabs
}
func makeBrowseUI() *fyne.Container {
// container for the image and surrounding elements
imgC := container.New(
layout.NewHBoxLayout(),
widget.NewButtonWithIcon("", theme.NavigateBackIcon(), func() {
log.Println("Previous comic")
}),
layout.NewSpacer(),
widget.NewLabel("img placeholder"),
layout.NewSpacer(),
widget.NewButtonWithIcon("", theme.NavigateNextIcon(), func() {
log.Println("Next comic")
}))
browseUI := container.New(
layout.NewVBoxLayout(),
layout.NewSpacer(),
container.NewCenter(
container.NewVBox(
&widget.Label{Text: "published on " + fmt.Sprint(time.Now().Date()), TextStyle: fyne.TextStyle{Italic: true}},
container.NewHBox(
&widget.Label{Text: "Comic Title", TextStyle: fyne.TextStyle{Bold: true}},
&widget.Label{Text: "(#1234)", TextStyle: fyne.TextStyle{Monospace: true}},
),
),
),
imgC,
layout.NewSpacer(),
container.NewCenter(
&widget.Label{Text: "Comic 'title text'", TextStyle: fyne.TextStyle{Italic: true}},
),
)
return browseUI
}