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

65 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-03-30 21:19:04 -06:00
import "git.tebibyte.media/sashakoshka/tomo/layouts"
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/elements/containers"
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(300, 2)
window.SetTitle("List Sidebar")
2023-03-30 21:19:04 -06:00
container := containers.NewContainer(layouts.Horizontal { true, true })
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) {
2023-01-24 14:41:12 -07:00
container.Warp (func () {
if currentPage != nil {
container.Disown(currentPage)
}
container.Adopt(newPage, true)
currentPage = newPage
})
}
2023-03-30 21:19:04 -06:00
intro := elements.NewLabel (
"The List element can be easily used as a sidebar. " +
"Click on entries to flip pages!", true)
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", "")
form := containers.NewContainer(layouts.Vertical { true, false})
form.Adopt(elements.NewLabel("I have:", false), false)
form.Adopt(elements.NewSpacer(true), false)
form.Adopt(elements.NewCheckbox("Skin", true), false)
form.Adopt(elements.NewCheckbox("Blood", false), false)
form.Adopt(elements.NewCheckbox("Bone", false), false)
2023-02-16 12:57:46 -07:00
art := testing.NewArtist()
2023-01-24 14:41:12 -07:00
2023-03-30 21:19:04 -06:00
list := elements.NewList (
elements.NewListEntry("button", func () { turnPage(button) }),
elements.NewListEntry("mouse", func () { turnPage(mouse) }),
elements.NewListEntry("input", func () { turnPage(input) }),
elements.NewListEntry("form", func () { turnPage(form) }),
elements.NewListEntry("art", func () { turnPage(art) }))
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()
}