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/input/main.go

65 lines
1.6 KiB
Go
Raw Normal View History

2023-01-17 22:38:58 -07:00
package main
import "git.tebibyte.media/sashakoshka/tomo"
2023-01-17 23:29:59 -07:00
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-17 22:38:58 -07:00
func main () {
tomo.Run(run)
}
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
2023-01-18 09:56:14 -07:00
window.SetTitle("Enter Details")
2023-04-18 14:18:30 -06:00
container := elements.NewVBox(elements.SpaceBoth)
2023-01-17 22:38:58 -07:00
window.Adopt(container)
2023-01-18 09:56:14 -07:00
// create inputs
2023-03-30 21:19:04 -06:00
firstName := elements.NewTextBox("First name", "")
lastName := elements.NewTextBox("Last name", "")
fingerLength := elements.NewTextBox("Length of fingers", "")
2023-04-21 14:47:15 -06:00
purpose := elements.NewComboBox (
"",
"Gaslight",
"Gatekeep",
"Girlboss")
2023-03-30 21:19:04 -06:00
button := elements.NewButton("Ok")
2023-01-17 23:29:59 -07:00
2023-01-18 09:56:14 -07:00
button.SetEnabled(false)
2023-01-17 23:29:59 -07:00
button.OnClick (func () {
2023-01-18 09:56:14 -07:00
// create a dialog displaying the results
2023-01-17 23:29:59 -07:00
popups.NewDialog (
popups.DialogKindInfo,
2023-03-30 21:19:04 -06:00
window,
2023-01-17 23:29:59 -07:00
"Profile",
2023-01-18 09:56:14 -07:00
firstName.Value() + " " + lastName.Value() +
"'s fingers\nmeasure in at " + fingerLength.Value() +
" feet.")
2023-01-17 23:29:59 -07:00
})
2023-01-18 09:56:14 -07:00
// enable the Ok button if all three inputs have text in them
check := func () {
button.SetEnabled (
2023-04-21 14:47:15 -06:00
firstName.Filled() &&
lastName.Filled() &&
fingerLength.Filled() &&
purpose.Filled())
2023-01-18 09:56:14 -07:00
}
firstName.OnChange(check)
lastName.OnChange(check)
fingerLength.OnChange(check)
2023-04-21 14:47:15 -06:00
purpose.OnChange(check)
2023-01-18 09:56:14 -07:00
// add elements to container
2023-04-18 14:18:30 -06:00
container.AdoptExpand(elements.NewLabel("Choose your words carefully."))
2023-04-21 14:47:15 -06:00
container.Adopt (
firstName, lastName,
fingerLength,
elements.NewLabel("Purpose:"),
purpose,
elements.NewLine(), button)
2023-01-17 22:38:58 -07:00
window.OnClose(tomo.Stop)
window.Show()
}