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/goroutines/main.go

46 lines
1.1 KiB
Go
Raw Normal View History

package main
import "os"
import "time"
import "git.tebibyte.media/sashakoshka/tomo"
2023-01-12 17:52:21 -07:00
import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
import "git.tebibyte.media/sashakoshka/tomo/layouts/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
os.Exit(0)
}
func run () {
2023-03-10 11:45:53 -07:00
window, _ := tomo.NewWindow(200, 216)
window.SetTitle("Clock")
container := containers.NewContainer(basicLayouts.Vertical { true, true })
2023-01-12 16:03:08 -07:00
window.Adopt(container)
2023-01-12 17:52:21 -07:00
clock := fun.NewAnalogClock(time.Now())
container.Adopt(clock, true)
2023-02-01 23:48:16 -07:00
label := basicElements.NewLabel(formatTime(), false)
2023-01-12 16:03:08 -07:00
container.Adopt(label, false)
2023-01-12 17:52:21 -07:00
window.OnClose(tomo.Stop)
window.Show()
2023-01-12 17:52:21 -07:00
go tick(label, clock)
}
func formatTime () (timeString string) {
return time.Now().Format("2006-01-02 15:04:05")
}
2023-02-01 23:48:16 -07:00
func tick (label *basicElements.Label, clock *fun.AnalogClock) {
for {
tomo.Do (func () {
label.SetText(formatTime())
clock.SetTime(time.Now())
})
time.Sleep(time.Second)
}
}