diff options
Diffstat (limited to 'go/ui/button.go')
| -rw-r--r-- | go/ui/button.go | 14 |
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 } |
