diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-01-26 22:16:10 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:44 +0100 |
| commit | 926ca5cdd20a39e3e05aaa3486cb166718dab5ca (patch) | |
| tree | 3d7bc8a0e1e0be1ce8d92d5503bdede878e718e9 /go/ui/button.go | |
| parent | 8720ebf9c74d9e11001772b5c00c293fa3a8b9e5 (diff) | |
| download | muhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.tar.gz muhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.zip | |
intermeditae commit
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 } |
