krampus19/alui/label.go

35 lines
740 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
TextAlign allg5.HorizontalAlignment
2019-12-19 05:59:45 +00:00
}
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)
2019-12-19 05:59:45 +00:00
}