Removed the need for a quit handler

This commit is contained in:
2022-11-16 11:08:30 -05:00
parent e030f8632b
commit cab280a371
5 changed files with 25 additions and 47 deletions

View File

@@ -10,7 +10,6 @@ import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
var application = &stone.Application { }
var currentTime = time.Time { }
var tickPing = make(chan(struct { }))
func main () {
application.SetTitle("hellorld")
@@ -29,27 +28,20 @@ func main () {
application.SetIcon([]image.Image { icon16, icon32 })
channel, err := application.Run()
if err != nil { panic(err) }
application.OnStart(onStart)
application.OnResize(onResize)
err = application.Run()
if err != nil { panic(err) }
}
func onStart () {
redraw()
go tick()
}
for {
select {
case <- tickPing:
redraw()
case event := <- channel:
switch event.(type) {
case stone.EventQuit:
os.Exit(0)
case stone.EventResize:
redraw()
}
}
}
func onResize () {
redraw()
}
func redraw () {
@@ -70,13 +62,12 @@ func redraw () {
application.SetRune(5, 1, ':')
application.SetRune(6, 1, rune(second / 10 + 48))
application.SetRune(7, 1, rune(second % 10 + 48))
application.Draw()
}
func tick () {
for {
tickPing <- struct { } { }
redraw()
application.Draw()
time.Sleep(time.Second)
}
}