This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/examples/popups/main.go

85 lines
2.2 KiB
Go
Raw Normal View History

2023-01-12 10:51:42 -07:00
package main
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"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
2023-01-12 10:51:42 -07:00
func main () {
tomo.Run(run)
}
func run () {
window, err := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
if err != nil { panic(err.Error()) }
2023-01-12 10:51:42 -07:00
window.SetTitle("Dialog Boxes")
container := elements.NewVBox(true, true)
2023-01-12 10:51:42 -07:00
window.Adopt(container)
2023-03-30 21:19:04 -06:00
container.Adopt(elements.NewLabel("Try out different dialogs:", false), true)
2023-01-12 10:51:42 -07:00
2023-03-30 21:19:04 -06:00
infoButton := elements.NewButton("popups.DialogKindInfo")
2023-01-12 10:51:42 -07:00
infoButton.OnClick (func () {
popups.NewDialog (
popups.DialogKindInfo,
window,
2023-01-12 10:51:42 -07:00
"Information",
"You are wacky")
})
container.Adopt(infoButton, false)
infoButton.Focus()
2023-01-12 10:51:42 -07:00
2023-03-30 21:19:04 -06:00
questionButton := elements.NewButton("popups.DialogKindQuestion")
2023-01-12 10:51:42 -07:00
questionButton.OnClick (func () {
popups.NewDialog (
popups.DialogKindQuestion,
window,
2023-01-12 10:51:42 -07:00
"The Big Question",
"Are you real?",
popups.Button { "Yes", func () { } },
popups.Button { "No", func () { } },
popups.Button { "Not sure", func () { } })
})
container.Adopt(questionButton, false)
2023-03-30 21:19:04 -06:00
warningButton := elements.NewButton("popups.DialogKindWarning")
2023-01-12 10:51:42 -07:00
warningButton.OnClick (func () {
popups.NewDialog (
2023-02-21 14:48:56 -07:00
popups.DialogKindWarning,
window,
2023-01-12 10:51:42 -07:00
"Warning",
"They are fast approaching.")
})
container.Adopt(warningButton, false)
2023-03-30 21:19:04 -06:00
errorButton := elements.NewButton("popups.DialogKindError")
2023-01-12 10:51:42 -07:00
errorButton.OnClick (func () {
popups.NewDialog (
2023-02-21 14:48:56 -07:00
popups.DialogKindError,
window,
2023-01-12 10:51:42 -07:00
"Error",
"There is nowhere left to go.")
})
container.Adopt(errorButton, false)
2023-04-10 14:47:03 -06:00
menuButton := elements.NewButton("menu")
menuButton.OnClick (func () {
2023-04-15 20:23:08 -06:00
// TODO: make a better way to get the bounds of something
2023-04-10 14:47:03 -06:00
menu, err := window.NewMenu (
tomo.Bounds(0, 0, 64, 64).
2023-04-15 20:23:08 -06:00
Add(menuButton.Entity().Bounds().Min))
2023-04-10 14:47:03 -06:00
if err != nil { println(err.Error()) }
menu.Adopt(elements.NewLabel("I'm a shy window...", true))
menu.Show()
})
container.Adopt(menuButton, false)
2023-03-30 21:19:04 -06:00
cancelButton := elements.NewButton("No thank you.")
2023-01-12 10:51:42 -07:00
cancelButton.OnClick(tomo.Stop)
container.Adopt(cancelButton, false)
window.OnClose(tomo.Stop)
window.Show()
}