38 lines
783 B
Go
38 lines
783 B
Go
package ui
|
|
|
|
import (
|
|
"opslag.de/schobers/geom"
|
|
)
|
|
|
|
type Label struct {
|
|
ControlBase
|
|
|
|
Text string
|
|
}
|
|
|
|
func BuildLabel(text string, factory func(*Label)) *Label {
|
|
var l = &Label{Text: text}
|
|
factory(l)
|
|
return l
|
|
}
|
|
|
|
func (l *Label) DesiredSize(ctx Context) geom.PointF32 {
|
|
var fontName = l.fontName(ctx)
|
|
var font = ctx.Renderer().Font(fontName)
|
|
var width = font.WidthOf(l.Text)
|
|
var height = font.Height()
|
|
var pad = ctx.Style().Dimensions.TextPadding
|
|
return geom.PtF32(width+pad*2, height+pad*2)
|
|
}
|
|
|
|
func (l *Label) Render(ctx Context) {
|
|
l.RenderBackground(ctx)
|
|
var c = l.FontColor
|
|
if c == nil {
|
|
c = ctx.Style().Palette.Text
|
|
}
|
|
var f = l.fontName(ctx)
|
|
var pad = ctx.Style().Dimensions.TextPadding
|
|
ctx.Renderer().Text(l.bounds.Min.Add(geom.PtF32(pad, pad)), f, c, l.Text)
|
|
}
|