zntg/ui/label.go
Sander Schobers 9d4b097352 Added Rect method to Control interface.
Fixed ContentScrollbar.
Added horizontal alignment to label.
Removed some dimensional constants.
Added several controls:
- Margin;
- Button;
- Columns;
- Scroll;
- Wrapper (reusable layout control) that wraps around existing control.
2018-09-09 21:07:53 +02:00

31 lines
668 B
Go

package ui
import (
"opslag.de/schobers/galleg/allegro5"
"opslag.de/schobers/geom"
)
type Label struct {
ControlBase
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))
}
func (l *Label) Render(ctx Context) {
var fonts = ctx.Fonts()
var min = l.Bounds.Min.To32()
var fnt = fonts.Get("default")
fnt.Draw(min.X, min.Y+fnt.Height()-fnt.Ascent(), ctx.Palette().Darkest(), l.HorizontalAlignment, l.Text)
l.ControlBase.Render(ctx)
}