aboutsummaryrefslogtreecommitdiff
path: root/go/ui/buffer.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2024-12-28 11:34:53 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:13 +0200
commitba4f24e71e4970c3095971fe6c5df7f829cab3e5 (patch)
treeb305956002f828dab115f2617fb039b5b8f5d0d7 /go/ui/buffer.go
parentbfab1b8f10ce006dd4822ac3e82125ec226597f5 (diff)
downloadmuhqs-game-ba4f24e71e4970c3095971fe6c5df7f829cab3e5.tar.gz
muhqs-game-ba4f24e71e4970c3095971fe6c5df7f829cab3e5.zip
migrate to ebiten/v2/text/v2
Diffstat (limited to 'go/ui/buffer.go')
-rw-r--r--go/ui/buffer.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/go/ui/buffer.go b/go/ui/buffer.go
index 201273b8..e46461bf 100644
--- a/go/ui/buffer.go
+++ b/go/ui/buffer.go
@@ -4,7 +4,7 @@ import (
"image/color"
"github.com/hajimehoshi/ebiten/v2"
- "github.com/hajimehoshi/ebiten/v2/text"
+ "github.com/hajimehoshi/ebiten/v2/text/v2"
"muhq.space/muhqs-game/go/font"
)
@@ -18,10 +18,13 @@ type Buffer struct {
WidgetBase
lines []string
pos int
+ font *text.GoTextFace
+ lineSpacing float64
+ xMargin float64
}
func NewBuffer(x, y int, width, height int) *Buffer {
- b := &Buffer{NewWidgetBase(x, y, width, height), []string{}, 0}
+ b := &Buffer{NewWidgetBase(x, y, width, height), []string{}, 0, font.Font18, 1.5, 10.}
b.renderImpl = func() *ebiten.Image { return b.render() }
return b
}
@@ -29,14 +32,18 @@ func NewBuffer(x, y int, width, height int) *Buffer {
func (b *Buffer) render() *ebiten.Image {
img := ebiten.NewImage(b.Width, b.Height)
img.Fill(BUFFER_BACKGROUND)
- y := 0
+ var y float64 = -b.font.Size
for _, line := range b.lines[b.pos:] {
- bounds := text.BoundString(font.Font18, line)
- y += bounds.Dy()
- if y > b.Height {
+ _, h := text.Measure(line, b.font, b.font.Size * b.lineSpacing)
+ y += h
+ if y > float64(b.Height) {
break
}
- text.Draw(img, line, font.Font18, 0, y, BUFFER_FOREGROUND)
+ op := &text.DrawOptions{}
+ op.ColorScale.ScaleWithColor(BUFFER_FOREGROUND)
+ op.GeoM.Translate(b.xMargin, float64(y))
+ op.LineSpacing = b.font.Size * b.lineSpacing
+ text.Draw(img, line, b.font, op)
}
return img
}