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")
2023-04-18 14:18:30 -06:00
container := elements.NewVBox(elements.SpaceBoth)
2023-01-12 10:51:42 -07:00
window.Adopt(container)
2023-04-18 14:18:30 -06:00
container.AdoptExpand(elements.NewLabel("Try out different dialogs:"))
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")
})
2023-04-18 14:18:30 -06:00
container.Adopt(infoButton)
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 () { } })
})
2023-04-18 14:18:30 -06:00
container.Adopt(questionButton)
2023-01-12 10:51:42 -07:00
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.")
})
2023-04-18 14:18:30 -06:00
container.Adopt(warningButton)
2023-01-12 10:51:42 -07:00
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.")
})
2023-04-18 14:18:30 -06:00
container.Adopt(errorButton)
2023-01-12 10:51:42 -07:00
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()) }
2023-04-18 14:18:30 -06:00
menu.Adopt(elements.NewLabelWrapped("I'm a shy window..."))
2023-04-10 14:47:03 -06:00
menu.Show()
})
2023-04-18 14:18:30 -06:00
container.Adopt(menuButton)
2023-04-10 14:47:03 -06:00
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)
2023-04-18 14:18:30 -06:00
container.Adopt(cancelButton)
2023-01-12 10:51:42 -07:00
window.OnClose(tomo.Stop)
window.Show()
}