Sander Schobers
11ab3fca0f
Added video settings. Added and improved reusable controls. Separated drawing of sprites. Fixed bug that text was right aligned instead of left aligned.
35 lines
740 B
Go
35 lines
740 B
Go
package alui
|
|
|
|
import (
|
|
"opslag.de/schobers/allg5"
|
|
"opslag.de/schobers/geom"
|
|
)
|
|
|
|
var _ Control = &Label{}
|
|
|
|
type Label struct {
|
|
ControlBase
|
|
|
|
Text string
|
|
TextAlign allg5.HorizontalAlignment
|
|
}
|
|
|
|
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.DrawAlign(l.Font, bounds.Min.X+4, bounds.Min.Y+4, bounds.Max.X-4, *fore, l.TextAlign, l.Text)
|
|
}
|