From 757758d8e96d4926e88eab0011744ad5b5847856 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Tue, 9 Jul 2019 19:07:40 +0200 Subject: [PATCH] Fixed right/center alignment of labels. --- ui/label.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ui/label.go b/ui/label.go index 96c588d..4d17d8c 100644 --- a/ui/label.go +++ b/ui/label.go @@ -36,5 +36,13 @@ func (l *Label) Render(ctx Context) { var c = l.FontColor(ctx) var f = l.FontName(ctx) 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) + } }