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.
Sasha Koshka 9aea6d8c0f List element's events make more sense
Removed redundant selected entry change event, and added an event
that fires when the user deselects the current element.
2023-01-26 12:05:28 -05:00

62 lines
1.8 KiB
Go

package main
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/layouts"
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")
container := basic.NewContainer(layouts.Horizontal { true, true })
window.Adopt(container)
var currentPage tomo.Element
turnPage := func (newPage tomo.Element) {
container.Warp (func () {
if currentPage != nil {
container.Disown(currentPage)
}
container.Adopt(newPage, true)
currentPage = newPage
})
}
intro := basic.NewLabel (
"The List element can be easily used as a sidebar. " +
"Click on entries to flip pages!", true)
button := basic.NewButton("I do nothing!")
button.OnClick (func () {
popups.NewDialog(popups.DialogKindInfo, "", "Sike!")
})
mouse := testing.NewMouse()
input := basic.NewTextBox("Write some text", "")
form := basic.NewContainer(layouts.Vertical { true, false})
form.Adopt(basic.NewLabel("I have:", false), false)
form.Adopt(basic.NewSpacer(true), false)
form.Adopt(basic.NewCheckbox("Skin", true), false)
form.Adopt(basic.NewCheckbox("Blood", false), false)
form.Adopt(basic.NewCheckbox("Bone", false), false)
list := basic.NewList (
basic.NewListEntry("button", func () { turnPage(button) }),
basic.NewListEntry("mouse", func () { turnPage(mouse) }),
basic.NewListEntry("input", func () { turnPage(input) }),
basic.NewListEntry("form", func () { turnPage(form) }))
list.OnNoEntrySelected(func () { turnPage (intro) })
list.Collapse(96, 0)
container.Adopt(list, false)
turnPage(intro)
window.OnClose(tomo.Stop)
window.Show()
}