From cca4e786516b132b893b56558c0141764a0f9ee5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 13 Nov 2023 22:58:19 +0900 Subject: [PATCH] examples/text: add an example to use alignments of text/v2 Closes #2143 --- examples/text/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/text/main.go b/examples/text/main.go index 5af49dbb4..8fcd13376 100644 --- a/examples/text/main.go +++ b/examples/text/main.go @@ -128,8 +128,12 @@ func (g *Game) Draw(screen *ebiten.Image) { w, h := text.Measure(sampleText, mplusBigFace, lineHeight) vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false) op := &text.DrawOptions{} - op.GeoM.Translate(x, y) + // Add the width as the text rendering region's upper-right position comes to (0, 0) + // when the horizontal alignment is right. The alignment is specified later (PrimaryAlign). + op.GeoM.Translate(x+w, y) op.LineHeightInPixels = lineHeight + // The primary alignment for the left-to-right direction is a horizontal alignment, and the end means the right. + op.PrimaryAlign = text.AlignEnd text.Draw(screen, sampleText, mplusBigFace, op) } {