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

45 lines
1002 B
Go
Raw Normal View History

package main
import "os"
import "time"
import "git.tebibyte.media/sashakoshka/tomo"
2023-03-30 21:19:04 -06:00
import "git.tebibyte.media/sashakoshka/tomo/elements"
2023-01-12 17:52:21 -07:00
import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
func main () {
tomo.Run(run)
os.Exit(0)
}
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 200, 216))
window.SetTitle("Clock")
2023-04-19 22:15:37 -06:00
window.SetApplicationName("TomoClock")
2023-04-18 14:18:30 -06:00
container := elements.NewVBox(elements.SpaceBoth)
2023-01-12 16:03:08 -07:00
window.Adopt(container)
2023-01-12 17:52:21 -07:00
clock := fun.NewAnalogClock(time.Now())
2023-04-18 14:18:30 -06:00
label := elements.NewLabel(formatTime())
container.AdoptExpand(clock)
container.Adopt(label)
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-03-30 21:19:04 -06:00
func tick (label *elements.Label, clock *fun.AnalogClock) {
for {
tomo.Do (func () {
label.SetText(formatTime())
clock.SetTime(time.Now())
})
time.Sleep(time.Second)
}
}