aboutsummaryrefslogtreecommitdiff
path: root/go/ui/textBox.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/ui/textBox.go')
-rw-r--r--go/ui/textBox.go91
1 files changed, 20 insertions, 71 deletions
diff --git a/go/ui/textBox.go b/go/ui/textBox.go
index f43e42b3..0e8adf5f 100644
--- a/go/ui/textBox.go
+++ b/go/ui/textBox.go
@@ -6,7 +6,6 @@ import (
"strconv"
"github.com/hajimehoshi/ebiten/v2"
- "github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text/v2"
"muhq.space/muhqs-game/go/font"
"muhq.space/muhqs-game/go/game"
@@ -23,26 +22,26 @@ var (
type TextBox struct {
WidgetBase
- text string
- fg color.Color
- bg color.Color
- font *text.GoTextFace
+ text string
+ fg color.Color
+ bg color.Color
+ font *text.GoTextFace
lineSpacing float64
- XMargin int
- YMargin int
- center bool
+ XMargin int
+ YMargin int
+ center bool
}
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,
- font: font.Font24,
+ WidgetBase: NewWidgetBase(x, y, width, height),
+ text: t,
+ fg: TEXTBOX_DEFAULT_FOREGROUND,
+ bg: TEXTBOX_DEFAULT_BACKGROUND,
+ font: font.Font24,
lineSpacing: 1.5,
- XMargin: TEXTBOX_DEFAULT_MARGIN,
- YMargin: TEXTBOX_DEFAULT_MARGIN,
+ XMargin: TEXTBOX_DEFAULT_MARGIN,
+ YMargin: TEXTBOX_DEFAULT_MARGIN,
}
tb.renderImpl = func() *ebiten.Image { return tb.render() }
return tb
@@ -105,7 +104,7 @@ func NewPermInfo(x, y int, p game.Permanent) *TextBox {
func (tb *TextBox) render() *ebiten.Image {
var x, y float64
- w, h := text.Measure(tb.text, tb.font, tb.font.Size * tb.lineSpacing)
+ w, h := text.Measure(tb.text, tb.font, tb.font.Size*tb.lineSpacing)
if tb.Width == -1 || tb.Height == -1 {
tb.Width = int(w) + 2*tb.XMargin
tb.Height = int(h) + 2*tb.YMargin
@@ -115,10 +114,10 @@ func (tb *TextBox) render() *ebiten.Image {
if !tb.center {
x = float64(tb.XMargin)
} else {
- x = (float64(tb.Width) - w)/2
+ x = (float64(tb.Width) - w) / 2
}
- y = (float64(tb.Height) - h)/2
+ y = (float64(tb.Height) - h) / 2
}
img := ebiten.NewImage(tb.Width, tb.Height)
@@ -169,7 +168,7 @@ func (w *PocList) setText() {
w.text = "No cards"
}
- width, height := text.Measure(w.text, w.font, w.font.Size * w.lineSpacing)
+ width, height := text.Measure(w.text, w.font, w.font.Size*w.lineSpacing)
w.X = w.centerX - int(width/2) - w.XMargin
w.Y = w.bottomY - int(height) - w.YMargin
}
@@ -186,7 +185,7 @@ func (w *PocList) FindObjectAt(_x, _y int) interface{} {
y := _y - w.Y
- _, height := text.Measure(w.text, w.font, w.font.Size * w.lineSpacing)
+ _, height := text.Measure(w.text, w.font, w.font.Size*w.lineSpacing)
i := y / (int(height) / w.poc.Size())
if i >= len(cards) {
@@ -196,56 +195,6 @@ func (w *PocList) FindObjectAt(_x, _y int) interface{} {
return cards[i]
}
-type TextInput struct {
- TextBox
- input string
- label string
-}
-
-func (ti *TextInput) InitTextInput(x, y int, width, height int, label string) {
- ti.TextBox = *(NewFixedTextBox(x, y, width, height, "").Centering(true))
- ti.input = ""
- ti.label = label
-
- ti.renderImpl = func() *ebiten.Image {
- if ti.input == "" {
- ti.text = ti.label
- } else {
- ti.text = ti.input
- }
-
- return ti.render()
- }
-}
-
-func NewTextInput(x, y int, width, height int, label string) *TextInput {
- w := &TextInput{}
- w.InitTextInput(x, y, width, height, label)
- return w
-}
-
-func (ti *TextInput) SetInput(input string) {
- ti.input = input
- ti.ForceRedraw()
-}
-
-func (ti *TextInput) AddInput(input []rune) {
- ti.SetInput(ti.input + string(input))
-}
-
-func (ti *TextInput) HandleKey() {
- if inpututil.IsKeyJustPressed(ebiten.KeyBackspace) {
- if len(ti.input) > 0 {
- ti.input = ti.input[:len(ti.input)-1]
- ti.ForceRedraw()
- }
- }
-}
-
-func (ti *TextInput) Text() string {
- return ti.input
-}
-
type NumberInput struct {
TextInput
n int
@@ -253,7 +202,7 @@ type NumberInput struct {
func NewNumberInput(x, y int, height, width int, number int) *NumberInput {
ni := &NumberInput{
- n: 0,
+ n: number,
}
ni.InitTextInput(x, y, width, height, strconv.Itoa(number))
return ni