zntg/ui/ui.go
Sander Schobers 19daffd110 Added UI elements.
Reversed order of operands when comparing with nil/0 .
2019-03-05 21:52:18 +01:00

31 lines
686 B
Go

package ui
import (
"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 {
ctx := &context{r: r, style: s, view: view, ims: NewImages()}
root, ok := view.(RootControl)
if ok {
root.Init(ctx)
}
for !ctx.quit {
var size = r.Size()
var bounds = geom.RectF32(0, 0, size.X, size.Y)
view.Arrange(ctx, bounds, geom.ZeroPtF32)
view.Render(ctx)
if ctx.quit {
return nil
}
r.PushEvents(ctx, wait)
}
return nil
}