allg5/alui/ui.go

48 lines
930 B
Go
Raw Normal View History

2020-03-08 09:10:41 +00:00
package alui
import (
"opslag.de/schobers/allg5"
"opslag.de/schobers/geom"
)
type UI struct {
ctx *Context
main Control
}
func NewUI(disp *allg5.Display, main Control) *UI {
ctx := &Context{
Display: disp,
Fonts: NewFonts(),
Palette: Palette{},
}
return &UI{ctx, main}
}
func (ui *UI) Context() *Context { return ui.ctx }
func (ui *UI) Destroy() {
ui.ctx.Fonts.Destroy()
}
func (ui *UI) Fonts() *Fonts { return ui.ctx.Fonts }
func (ui *UI) SetPalette(p Palette) { ui.ctx.Palette = p }
func (ui *UI) layoutBounds(bounds geom.RectangleF32) {
ui.main.Layout(ui.ctx, bounds)
}
func (ui *UI) Handle(e allg5.Event) { ui.main.Handle(e) }
func (ui *UI) Render() {
ui.RenderBounds(ui.ctx.DisplayBounds())
}
func (ui *UI) RenderBounds(bounds geom.RectangleF32) {
ui.ctx.Cursor = allg5.MouseCursorDefault
ui.layoutBounds(bounds)
ui.main.Render(ui.ctx, bounds)
ui.ctx.Display.SetMouseCursor(ui.ctx.Cursor)
}