aboutsummaryrefslogtreecommitdiff
path: root/go/ui/buffer.go
diff options
context:
space:
mode:
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
}