2023-02-09 16:34:53 -07: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-30 21:19:04 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
2023-03-15 23:14:39 -06:00
|
|
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
2023-03-16 12:22:56 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
2023-02-09 16:34:53 -07:00
|
|
|
|
|
|
|
func main () {
|
|
|
|
tomo.Run(run)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run () {
|
2023-04-15 20:23:08 -06:00
|
|
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
2023-02-09 16:34:53 -07:00
|
|
|
window.SetTitle("Tomo Logo")
|
|
|
|
|
|
|
|
file, err := os.Open("assets/banner.png")
|
2023-03-30 21:19:04 -06:00
|
|
|
if err != nil { fatalError(window, err); return }
|
2023-02-09 16:34:53 -07:00
|
|
|
logo, _, err := image.Decode(file)
|
|
|
|
file.Close()
|
2023-03-30 21:19:04 -06:00
|
|
|
if err != nil { fatalError(window, err); return }
|
2023-02-09 16:34:53 -07:00
|
|
|
|
2023-04-15 20:23:08 -06:00
|
|
|
container := containers.NewVBox(true, true)
|
2023-03-30 21:19:04 -06:00
|
|
|
logoImage := elements.NewImage(logo)
|
|
|
|
button := elements.NewButton("Show me a gopher instead")
|
2023-04-15 20:23:08 -06: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 }
|
|
|
|
container.Adopt(elements.NewImage(gopher),true)
|
|
|
|
})
|
2023-02-09 16:34:53 -07:00
|
|
|
|
|
|
|
container.Adopt(logoImage, true)
|
|
|
|
container.Adopt(button, false)
|
|
|
|
window.Adopt(container)
|
|
|
|
|
|
|
|
button.Focus()
|
|
|
|
|
|
|
|
window.OnClose(tomo.Stop)
|
|
|
|
window.Show()
|
|
|
|
}
|
|
|
|
|
2023-03-30 21:19:04 -06:00
|
|
|
func fatalError (window tomo.Window, err error) {
|
2023-02-09 16:34:53 -07:00
|
|
|
popups.NewDialog (
|
|
|
|
popups.DialogKindError,
|
2023-03-30 21:19:04 -06:00
|
|
|
window,
|
2023-02-09 16:34:53 -07:00
|
|
|
"Error",
|
|
|
|
err.Error(),
|
|
|
|
popups.Button {
|
|
|
|
Name: "OK",
|
|
|
|
OnPress: tomo.Stop,
|
|
|
|
})
|
|
|
|
}
|
2023-03-30 21:19:04 -06:00
|
|
|
|