2023-02-09 23:34:53 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "os"
|
|
|
|
import "image"
|
|
|
|
import "bytes"
|
|
|
|
import _ "image/png"
|
|
|
|
import "github.com/jezek/xgbutil/gopher"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/popups"
|
2023-03-31 03:19:04 +00:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
2023-03-16 05:14:39 +00:00
|
|
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
2023-02-09 23:34:53 +00:00
|
|
|
|
|
|
|
func main () {
|
|
|
|
tomo.Run(run)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run () {
|
2023-04-16 02:23:08 +00:00
|
|
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
2023-02-09 23:34:53 +00:00
|
|
|
window.SetTitle("Tomo Logo")
|
|
|
|
|
|
|
|
file, err := os.Open("assets/banner.png")
|
2023-03-31 03:19:04 +00:00
|
|
|
if err != nil { fatalError(window, err); return }
|
2023-02-09 23:34:53 +00:00
|
|
|
logo, _, err := image.Decode(file)
|
|
|
|
file.Close()
|
2023-03-31 03:19:04 +00:00
|
|
|
if err != nil { fatalError(window, err); return }
|
2023-02-09 23:34:53 +00:00
|
|
|
|
2023-04-18 20:18:30 +00:00
|
|
|
container := elements.NewVBox(elements.SpaceBoth)
|
2023-03-31 03:19:04 +00:00
|
|
|
logoImage := elements.NewImage(logo)
|
|
|
|
button := elements.NewButton("Show me a gopher instead")
|
2023-04-16 02:23:08 +00:00
|
|
|
button.OnClick (func () {
|
|
|
|
window.SetTitle("Not the Tomo Logo")
|
|
|
|
container.DisownAll()
|
|
|
|
gopher, _, err :=
|
|
|
|
image.Decode(bytes.NewReader(gopher.GopherPng()))
|
|
|
|
if err != nil { fatalError(window, err); return }
|
2023-04-18 20:18:30 +00:00
|
|
|
container.AdoptExpand(elements.NewImage(gopher))
|
2023-04-16 02:23:08 +00:00
|
|
|
})
|
2023-02-09 23:34:53 +00:00
|
|
|
|
2023-04-18 20:18:30 +00:00
|
|
|
container.AdoptExpand(logoImage)
|
|
|
|
container.Adopt(button)
|
2023-02-09 23:34:53 +00:00
|
|
|
window.Adopt(container)
|
|
|
|
|
|
|
|
button.Focus()
|
|
|
|
|
|
|
|
window.OnClose(tomo.Stop)
|
|
|
|
window.Show()
|
|
|
|
}
|
|
|
|
|
2023-03-31 03:19:04 +00:00
|
|
|
func fatalError (window tomo.Window, err error) {
|
2023-02-09 23:34:53 +00:00
|
|
|
popups.NewDialog (
|
|
|
|
popups.DialogKindError,
|
2023-03-31 03:19:04 +00:00
|
|
|
window,
|
2023-02-09 23:34:53 +00:00
|
|
|
"Error",
|
|
|
|
err.Error(),
|
|
|
|
popups.Button {
|
|
|
|
Name: "OK",
|
|
|
|
OnPress: tomo.Stop,
|
|
|
|
})
|
|
|
|
}
|
2023-03-31 03:19:04 +00:00
|
|
|
|