Fixed right/center alignment of labels.

This commit is contained in:
Sander Schobers 2019-07-09 19:07:40 +02:00
parent 432281f08d
commit 757758d8e9

View File

@ -36,5 +36,13 @@ func (l *Label) Render(ctx Context) {
var c = l.FontColor(ctx) var c = l.FontColor(ctx)
var f = l.FontName(ctx) var f = l.FontName(ctx)
var pad = ctx.Style().Dimensions.TextPadding var pad = ctx.Style().Dimensions.TextPadding
ctx.Renderer().TextAlign(l.bounds.Min.Add(geom.PtF32(pad, pad)), f, c, l.Text, l.TextAlignment) var bounds = l.bounds.Inset(pad)
switch l.TextAlignment {
case AlignLeft:
ctx.Renderer().TextAlign(bounds.Min, f, c, l.Text, l.TextAlignment)
case AlignRight:
ctx.Renderer().TextAlign(geom.PtF32(bounds.Max.X, bounds.Min.Y), f, c, l.Text, l.TextAlignment)
case AlignCenter:
ctx.Renderer().TextAlign(geom.PtF32(.5*(bounds.Min.X+bounds.Max.X), bounds.Min.Y), f, c, l.Text, l.TextAlignment)
}
} }