examples/text: add an example to use alignments of text/v2

Closes #2143
This commit is contained in:
Hajime Hoshi 2023-11-13 22:58:19 +09:00
parent 4a84f3697c
commit cca4e78651

View File

@ -128,8 +128,12 @@ func (g *Game) Draw(screen *ebiten.Image) {
w, h := text.Measure(sampleText, mplusBigFace, lineHeight) w, h := text.Measure(sampleText, mplusBigFace, lineHeight)
vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false) vector.DrawFilledRect(screen, x, y, float32(w), float32(h), gray, false)
op := &text.DrawOptions{} 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 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) text.Draw(screen, sampleText, mplusBigFace, op)
} }
{ {