2023-01-12 14:12:43 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
2023-05-02 23:26:51 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/nasin"
|
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"
|
2023-01-12 14:12:43 -07:00
|
|
|
|
|
|
|
func main () {
|
2023-05-02 23:26:51 -06:00
|
|
|
nasin.Run(Application { })
|
2023-01-12 14:12:43 -07:00
|
|
|
}
|
|
|
|
|
2023-05-02 23:26:51 -06:00
|
|
|
type Application struct { }
|
|
|
|
|
|
|
|
func (Application) Init () error {
|
|
|
|
window, err := nasin.NewWindow(tomo.Bounds(0, 0, 200, 216))
|
|
|
|
if err != nil { return err }
|
2023-02-08 19:05:36 -07:00
|
|
|
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
|
|
|
|
2023-05-02 23:26:51 -06:00
|
|
|
window.OnClose(nasin.Stop)
|
2023-01-12 14:12:43 -07:00
|
|
|
window.Show()
|
2023-01-12 17:52:21 -07:00
|
|
|
go tick(label, clock)
|
2023-05-02 23:26:51 -06:00
|
|
|
return nil
|
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-05-02 23:26:51 -06:00
|
|
|
nasin.Do (func () {
|
2023-01-17 18:16:03 -07:00
|
|
|
label.SetText(formatTime())
|
|
|
|
clock.SetTime(time.Now())
|
|
|
|
})
|
2023-01-12 14:12:43 -07:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}
|