aboutsummaryrefslogtreecommitdiff
path: root/go/ui/button.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-26 22:16:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:44 +0100
commit926ca5cdd20a39e3e05aaa3486cb166718dab5ca (patch)
tree3d7bc8a0e1e0be1ce8d92d5503bdede878e718e9 /go/ui/button.go
parent8720ebf9c74d9e11001772b5c00c293fa3a8b9e5 (diff)
downloadmuhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.tar.gz
muhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.zip
intermeditae commit
Diffstat (limited to 'go/ui/button.go')
-rw-r--r--go/ui/button.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/go/ui/button.go b/go/ui/button.go
index 97dbad22..6454ccac 100644
--- a/go/ui/button.go
+++ b/go/ui/button.go
@@ -32,9 +32,19 @@ func NewSimpleButton(x, y, w, h int, label string, onClick func(b *SimpleButton)
func (b *SimpleButton) render() *ebiten.Image {
img := ebiten.NewImage(b.Width, b.Height)
- // b := text.BoundString(f, label)
ebitenutil.DrawRect(img, float64(0), float64(0), float64(b.Width), float64(b.Height), b.BG)
- text.Draw(img, b.label, font.Font, 20, 25, b.FG)
+
+ bounds := text.BoundString(font.Font24, b.label)
+ x := (b.Width - bounds.Dx()) / 2
+ if x < 0 {
+ x = 0
+ }
+
+ y := b.Height - bounds.Dy()/2
+ if y < 0 {
+ y = 0
+ }
+ text.Draw(img, b.label, font.Font24, x, y, b.FG)
return img
}