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