2019-03-05 20:52:18 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
2019-04-10 19:20:39 +00:00
|
|
|
"time"
|
|
|
|
|
2019-03-05 20:52:18 +00:00
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Run runs the application loop.
|
|
|
|
func Run(r Renderer, s *Style, view Control) error {
|
|
|
|
return RunWait(r, s, view, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RunWait runs the application loop and conditionally waits on events before rendering.
|
|
|
|
func RunWait(r Renderer, s *Style, view Control, wait bool) error {
|
2020-05-15 13:42:24 +00:00
|
|
|
ctx := newContext(r, s, view)
|
|
|
|
defer ctx.Destroy()
|
|
|
|
|
2019-03-05 20:52:18 +00:00
|
|
|
root, ok := view.(RootControl)
|
|
|
|
if ok {
|
2019-05-01 07:40:59 +00:00
|
|
|
err := root.Init(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
2019-04-10 19:20:39 +00:00
|
|
|
anim := time.NewTicker(30 * time.Millisecond)
|
|
|
|
go func() {
|
2019-06-21 08:49:06 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-anim.C:
|
|
|
|
case <-ctx.quit:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ctx.animate {
|
2019-04-10 19:20:39 +00:00
|
|
|
r.Refresh()
|
|
|
|
}
|
|
|
|
ctx.animate = false
|
|
|
|
}
|
|
|
|
}()
|
2019-06-21 08:49:06 +00:00
|
|
|
defer anim.Stop()
|
|
|
|
|
2020-05-15 14:02:54 +00:00
|
|
|
overlays := ctx.Overlays()
|
2019-04-10 19:20:39 +00:00
|
|
|
ctx.Renderer().Refresh()
|
2019-06-21 08:49:06 +00:00
|
|
|
for !ctx.HasQuit() {
|
2019-03-05 20:52:18 +00:00
|
|
|
var size = r.Size()
|
|
|
|
var bounds = geom.RectF32(0, 0, size.X, size.Y)
|
2020-05-15 14:02:54 +00:00
|
|
|
overlays.Arrange(ctx, bounds, geom.ZeroPtF32, nil)
|
|
|
|
overlays.Render(ctx)
|
2019-06-21 08:49:06 +00:00
|
|
|
if ctx.HasQuit() {
|
2019-03-05 20:52:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-05-15 14:39:53 +00:00
|
|
|
|
2020-05-17 05:21:58 +00:00
|
|
|
tooltip := ctx.tooltip.Text
|
|
|
|
ctx.tooltip.Text = ""
|
2019-03-05 20:52:18 +00:00
|
|
|
r.PushEvents(ctx, wait)
|
2020-05-17 05:21:58 +00:00
|
|
|
if ctx.tooltip.Text != tooltip {
|
|
|
|
ctx.overlays.SetVisibility(uiDefaultTooltipOverlay, ctx.tooltip.Text != "")
|
|
|
|
}
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|