2018-08-03 06:46:10 +00:00
|
|
|
package ui
|
|
|
|
|
2018-09-09 19:07:53 +00:00
|
|
|
import (
|
|
|
|
"opslag.de/schobers/geom"
|
2018-09-23 07:42:23 +00:00
|
|
|
"opslag.de/schobers/zntg/allg5"
|
2018-09-09 19:07:53 +00:00
|
|
|
)
|
2018-08-03 06:46:10 +00:00
|
|
|
|
|
|
|
type Label struct {
|
|
|
|
ControlBase
|
2018-09-09 19:07:53 +00:00
|
|
|
Text string
|
2018-09-22 14:23:26 +00:00
|
|
|
HorizontalAlignment allg5.HorizontalAlignment
|
2018-09-09 19:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 07:42:23 +00:00
|
|
|
func (l *Label) DesiredSize(ctx Context) geom.PointF32 {
|
2018-09-09 19:07:53 +00:00
|
|
|
var fonts = ctx.Fonts()
|
|
|
|
var fnt = fonts.Get("default")
|
|
|
|
var _, _, w, h = fnt.TextDimensions(l.Text)
|
2018-09-23 07:42:23 +00:00
|
|
|
return geom.PtF32(w, h)
|
2018-08-03 06:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Label) Render(ctx Context) {
|
|
|
|
var fonts = ctx.Fonts()
|
|
|
|
|
2018-09-23 07:42:23 +00:00
|
|
|
var min = l.Bounds.Min
|
2018-08-03 06:46:10 +00:00
|
|
|
|
|
|
|
var fnt = fonts.Get("default")
|
2018-09-09 19:07:53 +00:00
|
|
|
fnt.Draw(min.X, min.Y+fnt.Height()-fnt.Ascent(), ctx.Palette().Darkest(), l.HorizontalAlignment, l.Text)
|
2018-08-03 06:46:10 +00:00
|
|
|
|
|
|
|
l.ControlBase.Render(ctx)
|
|
|
|
}
|