mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples/text: add an example to use alignments of text/v2
Closes #2143
This commit is contained in:
parent
4a84f3697c
commit
cca4e78651
@ -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)
|
||||
}
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user