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

70 lines
1.9 KiB
Go
Raw Normal View History

2023-01-24 14:41:12 -07:00
package main
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/popups"
2023-02-01 23:48:16 -07:00
import "git.tebibyte.media/sashakoshka/tomo/elements"
2023-01-24 14:41:12 -07:00
import "git.tebibyte.media/sashakoshka/tomo/elements/testing"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
2023-01-24 14:41:12 -07:00
func main () {
tomo.Run(run)
}
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 300, 0))
2023-01-24 14:41:12 -07:00
window.SetTitle("List Sidebar")
2023-04-18 14:18:30 -06:00
container := elements.NewHBox(elements.SpaceBoth)
2023-01-24 14:41:12 -07:00
window.Adopt(container)
2023-03-30 21:19:04 -06:00
var currentPage tomo.Element
turnPage := func (newPage tomo.Element) {
if currentPage != nil {
container.Disown(currentPage)
}
2023-04-18 14:18:30 -06:00
container.AdoptExpand(newPage)
currentPage = newPage
2023-01-24 14:41:12 -07:00
}
2023-04-18 14:18:30 -06:00
intro := elements.NewLabelWrapped (
"The List element can be easily used as a sidebar. " +
2023-04-18 14:18:30 -06:00
"Click on entries to flip pages!")
2023-03-30 21:19:04 -06:00
button := elements.NewButton("I do nothing!")
2023-01-24 14:41:12 -07:00
button.OnClick (func () {
2023-03-30 21:19:04 -06:00
popups.NewDialog(popups.DialogKindInfo, window, "", "Sike!")
2023-01-24 14:41:12 -07:00
})
mouse := testing.NewMouse()
2023-03-30 21:19:04 -06:00
input := elements.NewTextBox("Write some text", "")
2023-04-18 14:18:30 -06:00
form := elements.NewVBox (
elements.SpaceMargin,
elements.NewLabel("I have:"),
elements.NewLine(),
elements.NewCheckbox("Skin", true),
elements.NewCheckbox("Blood", false),
elements.NewCheckbox("Bone", false))
2023-02-16 12:57:46 -07:00
art := testing.NewArtist()
2023-01-24 14:41:12 -07:00
makePage := func (name string, callback func ()) tomo.Selectable {
2023-04-18 14:18:30 -06:00
cell := elements.NewCell(elements.NewLabel(name))
cell.OnSelectionChange (func () {
if cell.Selected() { callback() }
})
return cell
}
2023-03-30 21:19:04 -06:00
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) }))
2023-01-24 14:41:12 -07:00
list.Collapse(96, 0)
2023-04-18 14:18:30 -06:00
container.Adopt(list)
turnPage(intro)
2023-01-24 14:41:12 -07:00
window.OnClose(tomo.Stop)
window.Show()
}