2023-01-12 14:12:43 -07:00
|
|
|
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/layouts"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
2023-01-12 17:52:21 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
|
2023-03-15 23:14:39 -06:00
|
|
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
2023-03-16 12:22:56 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
2023-01-12 14:12:43 -07:00
|
|
|
|
|
|
|
func main () {
|
|
|
|
tomo.Run(run)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run () {
|
2023-04-10 00:58:52 -06:00
|
|
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 200, 216))
|
2023-02-08 19:05:36 -07:00
|
|
|
window.SetTitle("Clock")
|
2023-03-30 21:19:04 -06:00
|
|
|
container := containers.NewContainer(layouts.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-03-30 21:19:04 -06:00
|
|
|
label := elements.NewLabel(formatTime(), false)
|
2023-01-12 16:03:08 -07:00
|
|
|
container.Adopt(label, false)
|
2023-01-12 17:52:21 -07:00
|
|
|
|
2023-01-12 14:12:43 -07:00
|
|
|
window.OnClose(tomo.Stop)
|
|
|
|
window.Show()
|
2023-01-12 17:52:21 -07:00
|
|
|
go tick(label, clock)
|
2023-01-12 14:12:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2023-01-12 14:12:43 -07:00
|
|
|
for {
|
2023-01-17 18:16:03 -07:00
|
|
|
tomo.Do (func () {
|
|
|
|
label.SetText(formatTime())
|
|
|
|
clock.SetTime(time.Now())
|
|
|
|
})
|
2023-01-12 14:12:43 -07:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}
|