aboutsummaryrefslogtreecommitdiff
path: root/go/ui/textBox.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-14 09:52:22 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:50:09 +0200
commit1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c (patch)
tree23f6a6475340ea52026d2dea117e33c28b3a9df1 /go/ui/textBox.go
parent97d5079e68624f842938e4c87386752f1cfda649 (diff)
downloadmuhqs-game-1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c.tar.gz
muhqs-game-1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c.zip
improve state bar
Diffstat (limited to 'go/ui/textBox.go')
-rw-r--r--go/ui/textBox.go58
1 files changed, 31 insertions, 27 deletions
diff --git a/go/ui/textBox.go b/go/ui/textBox.go
index 58a3e679..1c82a307 100644
--- a/go/ui/textBox.go
+++ b/go/ui/textBox.go
@@ -12,46 +12,54 @@ import (
)
var (
- TEXTBOX_DEFAULT_BACKGROUND = gray
+ TEXTBOX_DEFAULT_BACKGROUND = color.Black
TEXTBOX_DEFAULT_FOREGROUND = color.White
TEXTBOX_DEFAULT_MARGIN = 3
+
+ TEXTBOX_AUTO_DIMENSION = -1
)
type TextBox struct {
WidgetBase
text string
- Fg color.Color
- Bg color.Color
+ fg color.Color
+ bg color.Color
XMargin int
YMargin int
- Center bool
+ center bool
}
-func NewFixedTextBox(x, y int, width, height int, t string, center bool) *TextBox {
+func NewFixedTextBox(x, y int, width, height int, t string) *TextBox {
tb := &TextBox{
WidgetBase: NewWidgetBase(x, y, width, height),
text: t,
- Fg: TEXTBOX_DEFAULT_FOREGROUND,
- Bg: TEXTBOX_DEFAULT_BACKGROUND,
+ fg: TEXTBOX_DEFAULT_FOREGROUND,
+ bg: TEXTBOX_DEFAULT_BACKGROUND,
XMargin: TEXTBOX_DEFAULT_MARGIN,
YMargin: TEXTBOX_DEFAULT_MARGIN,
- Center: center,
}
tb.renderImpl = func() *ebiten.Image { return tb.render() }
return tb
}
-func NewCenteringFixedTextBox(x, y int, width, height int, t string) *TextBox {
- return NewFixedTextBox(x, y, width, height, t, true)
+func NewAutoTextBox(x, y int, text string) *TextBox {
+ return NewFixedTextBox(x, y, TEXTBOX_AUTO_DIMENSION, TEXTBOX_AUTO_DIMENSION, text)
}
-func NewAutoTextBox(x, y int, t string) *TextBox {
- return NewFixedTextBox(x, y, -1, -1, t, false)
+func (tb *TextBox) Bg(bg color.Color) *TextBox {
+ tb.bg = bg
+ return tb
}
-func NewCenteringAutoTextBox(x, y int, t string) *TextBox {
- return NewFixedTextBox(x, y, -1, -1, t, true)
+func (tb *TextBox) Fg(fg color.Color) *TextBox {
+ tb.fg = fg
+ return tb
+}
+
+func (tb *TextBox) Centering(centering bool) *TextBox {
+ tb.center = centering
+ return tb
}
func NewUnitInfo(x, y int, u *game.Unit) *TextBox {
@@ -90,7 +98,7 @@ func (tb *TextBox) render() *ebiten.Image {
x = tb.XMargin + b.Min.X
y = tb.YMargin - b.Min.Y
} else {
- if !tb.Center {
+ if !tb.center {
x = tb.XMargin + b.Min.X
} else {
x = tb.Width/2 - centerTextXOffset(b)
@@ -100,8 +108,8 @@ func (tb *TextBox) render() *ebiten.Image {
}
img := ebiten.NewImage(tb.Width, tb.Height)
- img.Fill(tb.Bg)
- text.Draw(img, tb.text, font.Font24, x, y, tb.Fg)
+ img.Fill(tb.bg)
+ text.Draw(img, tb.text, font.Font24, x, y, tb.fg)
return img
}
@@ -114,15 +122,7 @@ type PocList struct {
func NewPocList(centerX, bottomY int, poc game.PileOfCards) *PocList {
w := &PocList{
- TextBox: TextBox{
- WidgetBase: NewWidgetBase(-1, -1, -1, -1),
- text: "",
- Fg: TEXTBOX_DEFAULT_FOREGROUND,
- Bg: TEXTBOX_DEFAULT_BACKGROUND,
- XMargin: TEXTBOX_DEFAULT_MARGIN,
- YMargin: TEXTBOX_DEFAULT_MARGIN,
- Center: true,
- },
+ TextBox: *(NewAutoTextBox(-1, -1, "").Centering(true)),
centerX: centerX,
bottomY: bottomY,
poc: poc,
@@ -169,7 +169,11 @@ type TextInput struct {
}
func NewTextInput(x, y int, width, height int, label string) *TextInput {
- w := &TextInput{*NewCenteringFixedTextBox(x, y, width, height, ""), "", label}
+ w := &TextInput{
+ TextBox: *(NewFixedTextBox(x, y, width, height, "").Centering(true)),
+ input: "",
+ label: label,
+ }
w.renderImpl = func() *ebiten.Image {
if w.input == "" {