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