Sander Schobers
0cd5cb4ad1
Refactored some structs from public to internal. Separated navigation from game. Added utility methods for drawing text. Stackpanel will uses all available width when layouting.
34 lines
664 B
Go
34 lines
664 B
Go
package alui
|
|
|
|
import (
|
|
"opslag.de/schobers/allg5"
|
|
"opslag.de/schobers/geom"
|
|
)
|
|
|
|
var _ Control = &Label{}
|
|
|
|
type Label struct {
|
|
ControlBase
|
|
|
|
Text string
|
|
}
|
|
|
|
func (l *Label) DesiredSize(ctx *Context) geom.PointF32 {
|
|
font := ctx.Fonts.Get(l.Font)
|
|
_, _, w, h := font.TextDimensions(l.Text)
|
|
return geom.PtF32(w+8, h+8)
|
|
}
|
|
|
|
func (l *Label) Render(ctx *Context, bounds geom.RectangleF32) {
|
|
back := l.Background
|
|
fore := l.Foreground
|
|
if fore == nil {
|
|
fore = &ctx.Palette.Text
|
|
}
|
|
|
|
if back != nil {
|
|
allg5.DrawFilledRectangle(bounds.Min.X, bounds.Min.Y, bounds.Max.X, bounds.Max.Y, *back)
|
|
}
|
|
ctx.Fonts.Draw(l.Font, bounds.Min.X+4, bounds.Min.Y+4, *fore, l.Text)
|
|
}
|