2018-08-03 06:46:10 +00:00
|
|
|
package ui
|
|
|
|
|
2018-09-09 19:07:53 +00:00
|
|
|
import (
|
|
|
|
"opslag.de/schobers/galleg/allegro5"
|
|
|
|
"opslag.de/schobers/geom"
|
|
|
|
)
|
2018-08-03 06:46:10 +00:00
|
|
|
|
|
|
|
type Label struct {
|
|
|
|
ControlBase
|
2018-09-09 19:07:53 +00:00
|
|
|
Text string
|
|
|
|
HorizontalAlignment allegro5.HorizontalAlignment
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Label) DesiredSize(ctx Context) geom.PointF {
|
|
|
|
var fonts = ctx.Fonts()
|
|
|
|
var fnt = fonts.Get("default")
|
|
|
|
var _, _, w, h = fnt.TextDimensions(l.Text)
|
|
|
|
return geom.PtF(float64(w), float64(h))
|
2018-08-03 06:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Label) Render(ctx Context) {
|
|
|
|
var fonts = ctx.Fonts()
|
|
|
|
|
|
|
|
var min = l.Bounds.Min.To32()
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|