Added support for animations.
This commit is contained in:
parent
552de0c748
commit
fa7796a4ae
@ -1,6 +1,7 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
type Context interface {
|
type Context interface {
|
||||||
|
Animate()
|
||||||
HasQuit() bool
|
HasQuit() bool
|
||||||
Images() *Images
|
Images() *Images
|
||||||
Quit()
|
Quit()
|
||||||
@ -12,6 +13,7 @@ var _ Context = &context{}
|
|||||||
var _ EventTarget = &context{}
|
var _ EventTarget = &context{}
|
||||||
|
|
||||||
type context struct {
|
type context struct {
|
||||||
|
animate bool
|
||||||
quit bool
|
quit bool
|
||||||
r Renderer
|
r Renderer
|
||||||
view Control
|
view Control
|
||||||
@ -19,6 +21,8 @@ type context struct {
|
|||||||
style *Style
|
style *Style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *context) Animate() { c.animate = true }
|
||||||
|
|
||||||
func (c *context) HasQuit() bool { return c.quit }
|
func (c *context) HasQuit() bool { return c.quit }
|
||||||
|
|
||||||
func (c *context) Images() *Images { return c.ims }
|
func (c *context) Images() *Images { return c.ims }
|
||||||
|
13
ui/ui.go
13
ui/ui.go
@ -1,6 +1,8 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +18,16 @@ func RunWait(r Renderer, s *Style, view Control, wait bool) error {
|
|||||||
if ok {
|
if ok {
|
||||||
root.Init(ctx)
|
root.Init(ctx)
|
||||||
}
|
}
|
||||||
|
anim := time.NewTicker(30 * time.Millisecond)
|
||||||
|
go func() {
|
||||||
|
for range anim.C {
|
||||||
|
if ctx.animate && !ctx.quit {
|
||||||
|
r.Refresh()
|
||||||
|
}
|
||||||
|
ctx.animate = false
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
ctx.Renderer().Refresh()
|
||||||
for !ctx.quit {
|
for !ctx.quit {
|
||||||
var size = r.Size()
|
var size = r.Size()
|
||||||
var bounds = geom.RectF32(0, 0, size.X, size.Y)
|
var bounds = geom.RectF32(0, 0, size.X, size.Y)
|
||||||
@ -26,5 +38,6 @@ func RunWait(r Renderer, s *Style, view Control, wait bool) error {
|
|||||||
}
|
}
|
||||||
r.PushEvents(ctx, wait)
|
r.PushEvents(ctx, wait)
|
||||||
}
|
}
|
||||||
|
anim.Stop()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user