Analog clock widget!!

This commit is contained in:
Sasha Koshka
2023-01-12 19:52:21 -05:00
parent 60c2ccbec2
commit b5469e103d
2 changed files with 96 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package main
import "os"
import "time"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/layouts"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/x"
@@ -17,20 +18,25 @@ func run () {
window.SetTitle("clock")
container := basic.NewContainer(layouts.Vertical { true, true })
window.Adopt(container)
clock := fun.NewAnalogClock(time.Now())
container.Adopt(clock, true)
label := basic.NewLabel(formatTime(), false)
container.Adopt(label, false)
window.OnClose(tomo.Stop)
window.Show()
go tick(label)
go tick(label, clock)
}
func formatTime () (timeString string) {
return time.Now().Format("2006-01-02 15:04:05")
}
func tick (label *basic.Label) {
func tick (label *basic.Label, clock *fun.AnalogClock) {
for {
label.SetText(formatTime())
clock.SetTime(time.Now())
time.Sleep(time.Second)
}
}