krampus19/alui/label.go

34 lines
664 B
Go
Raw Permalink Normal View History

2019-12-19 05:59:45 +00:00
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)
2019-12-19 05:59:45 +00:00
}