35 lines
739 B
Go
35 lines
739 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(ctx)
|
|
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)
|
|
}
|