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

63 lines
2.0 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"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
2023-01-24 14:41:12 -07:00
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/testing"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"
func main () {
tomo.Run(run)
}
func run () {
window, _ := tomo.NewWindow(300, 2)
window.SetTitle("List Sidebar")
2023-02-01 23:48:16 -07:00
container := basicElements.NewContainer(basicLayouts.Horizontal { true, true })
2023-01-24 14:41:12 -07:00
window.Adopt(container)
2023-02-01 23:48:16 -07:00
var currentPage elements.Element
turnPage := func (newPage elements.Element) {
2023-01-24 14:41:12 -07:00
container.Warp (func () {
if currentPage != nil {
container.Disown(currentPage)
}
container.Adopt(newPage, true)
currentPage = newPage
})
}
2023-02-01 23:48:16 -07:00
intro := basicElements.NewLabel (
"The List element can be easily used as a sidebar. " +
"Click on entries to flip pages!", true)
2023-02-01 23:48:16 -07:00
button := basicElements.NewButton("I do nothing!")
2023-01-24 14:41:12 -07:00
button.OnClick (func () {
popups.NewDialog(popups.DialogKindInfo, "", "Sike!")
})
mouse := testing.NewMouse()
2023-02-01 23:48:16 -07:00
input := basicElements.NewTextBox("Write some text", "")
form := basicElements.NewContainer(basicLayouts.Vertical { true, false})
form.Adopt(basicElements.NewLabel("I have:", false), false)
form.Adopt(basicElements.NewSpacer(true), false)
form.Adopt(basicElements.NewCheckbox("Skin", true), false)
form.Adopt(basicElements.NewCheckbox("Blood", false), false)
form.Adopt(basicElements.NewCheckbox("Bone", false), false)
2023-01-24 14:41:12 -07:00
2023-02-01 23:48:16 -07:00
list := basicElements.NewList (
basicElements.NewListEntry("button", func () { turnPage(button) }),
basicElements.NewListEntry("mouse", func () { turnPage(mouse) }),
basicElements.NewListEntry("input", func () { turnPage(input) }),
basicElements.NewListEntry("form", func () { turnPage(form) }))
list.OnNoEntrySelected(func () { turnPage (intro) })
2023-01-24 14:41:12 -07:00
list.Collapse(96, 0)
container.Adopt(list, false)
turnPage(intro)
2023-01-24 14:41:12 -07:00
window.OnClose(tomo.Stop)
window.Show()
}