From 1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 14 Feb 2023 09:52:22 +0100 Subject: improve state bar --- go/ui/textBox.go | 58 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'go/ui/textBox.go') 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 == "" { -- cgit v1.2.3