2023-04-04 00:01:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
|
|
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
|
|
|
|
|
|
|
func main () {
|
|
|
|
tomo.Run(run)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run () {
|
|
|
|
window, _ := tomo.NewWindow(2, 2)
|
|
|
|
window.SetTitle("Table")
|
|
|
|
|
|
|
|
container := containers.NewContainer(layouts.Vertical { true, true })
|
|
|
|
table := containers.NewTableContainer(7, 7, true, true)
|
2023-04-04 03:09:02 +00:00
|
|
|
scroller := containers.NewScrollContainer(true, true)
|
2023-04-04 00:01:44 +00:00
|
|
|
|
|
|
|
index := 0
|
|
|
|
for row := 0; row < 7; row ++ {
|
|
|
|
for column := 0; column < 7; column ++ {
|
|
|
|
if index % 2 == 0 {
|
|
|
|
label := elements.NewLabel (
|
|
|
|
fmt.Sprintf("%d, %d", row, column),
|
|
|
|
false)
|
|
|
|
table.Set(row, column, label)
|
|
|
|
}
|
|
|
|
index ++
|
|
|
|
}}
|
2023-04-04 03:09:02 +00:00
|
|
|
table.Set(2, 1, elements.NewButton("Oh hi mars!"))
|
2023-04-04 00:01:44 +00:00
|
|
|
|
2023-04-04 02:22:29 +00:00
|
|
|
statusLabel := elements.NewLabel("Selected: none", false)
|
2023-04-04 03:09:02 +00:00
|
|
|
table.Collapse(128, 128)
|
2023-04-04 02:22:29 +00:00
|
|
|
table.OnSelect (func () {
|
|
|
|
column, row := table.Selected()
|
|
|
|
statusLabel.SetText (
|
|
|
|
fmt.Sprintf("Selected: %d, %d",
|
|
|
|
column, row))
|
|
|
|
})
|
|
|
|
|
2023-04-04 03:09:02 +00:00
|
|
|
scroller.Adopt(table)
|
|
|
|
container.Adopt(scroller, true)
|
2023-04-04 02:22:29 +00:00
|
|
|
container.Adopt(statusLabel, false)
|
2023-04-04 00:01:44 +00:00
|
|
|
window.Adopt(container)
|
2023-04-04 01:41:39 +00:00
|
|
|
|
2023-04-04 00:01:44 +00:00
|
|
|
window.OnClose(tomo.Stop)
|
|
|
|
window.Show()
|
|
|
|
}
|