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/list/main.go
2023-04-18 16:18:30 -04:00

70 lines
1.9 KiB
Go

package main
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/elements"
import "git.tebibyte.media/sashakoshka/tomo/elements/testing"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
tomo.Run(run)
}
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 300, 0))
window.SetTitle("List Sidebar")
container := elements.NewHBox(elements.SpaceBoth)
window.Adopt(container)
var currentPage tomo.Element
turnPage := func (newPage tomo.Element) {
if currentPage != nil {
container.Disown(currentPage)
}
container.AdoptExpand(newPage)
currentPage = newPage
}
intro := elements.NewLabelWrapped (
"The List element can be easily used as a sidebar. " +
"Click on entries to flip pages!")
button := elements.NewButton("I do nothing!")
button.OnClick (func () {
popups.NewDialog(popups.DialogKindInfo, window, "", "Sike!")
})
mouse := testing.NewMouse()
input := elements.NewTextBox("Write some text", "")
form := elements.NewVBox (
elements.SpaceMargin,
elements.NewLabel("I have:"),
elements.NewLine(),
elements.NewCheckbox("Skin", true),
elements.NewCheckbox("Blood", false),
elements.NewCheckbox("Bone", false))
art := testing.NewArtist()
makePage := func (name string, callback func ()) tomo.Selectable {
cell := elements.NewCell(elements.NewLabel(name))
cell.OnSelectionChange (func () {
if cell.Selected() { callback() }
})
return cell
}
list := elements.NewList (
1,
makePage("button", func () { turnPage(button) }),
makePage("mouse", func () { turnPage(mouse) }),
makePage("input", func () { turnPage(input) }),
makePage("form", func () { turnPage(form) }),
makePage("art", func () { turnPage(art) }))
list.Collapse(96, 0)
container.Adopt(list)
turnPage(intro)
window.OnClose(tomo.Stop)
window.Show()
}