2019-03-05 20:52:18 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Label struct {
|
|
|
|
ControlBase
|
|
|
|
|
|
|
|
Text string
|
|
|
|
}
|
|
|
|
|
2019-03-12 20:11:43 +00:00
|
|
|
func BuildLabel(text string, fn func(*Label)) *Label {
|
2019-03-05 20:52:18 +00:00
|
|
|
var l = &Label{Text: text}
|
2019-03-12 20:11:43 +00:00
|
|
|
if fn != nil {
|
|
|
|
fn(l)
|
|
|
|
}
|
2019-03-05 20:52:18 +00:00
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Label) DesiredSize(ctx Context) geom.PointF32 {
|
2019-03-12 18:43:52 +00:00
|
|
|
var fontName = l.FontName(ctx)
|
2019-03-05 20:52:18 +00:00
|
|
|
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)
|
2019-03-12 18:43:52 +00:00
|
|
|
var c = l.FontColor(ctx)
|
|
|
|
var f = l.FontName(ctx)
|
2019-03-05 20:52:18 +00:00
|
|
|
var pad = ctx.Style().Dimensions.TextPadding
|
2019-06-24 18:58:14 +00:00
|
|
|
ctx.Renderer().TextAlign(l.bounds.Min.Add(geom.PtF32(pad, pad)), f, c, l.Text, l.TextAlignment)
|
2019-03-05 20:52:18 +00:00
|
|
|
}
|