diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2024-12-26 19:05:45 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:11 +0200 |
| commit | 74bc10b2ef3ff5eba902295fd139ac60d4333f51 (patch) | |
| tree | 2ce18dea4a547dbbaad48a511515acb846b84352 /go/ui/textBox.go | |
| parent | 59cf4dd9b651c10bc323985d68c37a1053837f40 (diff) | |
| download | muhqs-game-74bc10b2ef3ff5eba902295fd139ac60d4333f51.tar.gz muhqs-game-74bc10b2ef3ff5eba902295fd139ac60d4333f51.zip | |
ui: add new number choice
Diffstat (limited to 'go/ui/textBox.go')
| -rw-r--r-- | go/ui/textBox.go | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/go/ui/textBox.go b/go/ui/textBox.go index 66b90698..4fc2b533 100644 --- a/go/ui/textBox.go +++ b/go/ui/textBox.go @@ -3,6 +3,7 @@ package ui import ( "fmt" "image/color" + "strconv" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" @@ -193,23 +194,25 @@ type TextInput struct { label string } -func NewTextInput(x, y int, width, height int, label string) *TextInput { - w := &TextInput{ - TextBox: *(NewFixedTextBox(x, y, width, height, "").Centering(true)), - input: "", - label: label, - } +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 - w.renderImpl = func() *ebiten.Image { - if w.input == "" { - w.text = w.label + ti.renderImpl = func() *ebiten.Image { + if ti.input == "" { + ti.text = ti.label } else { - w.text = w.input + ti.text = ti.input } - return w.render() + 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 } @@ -234,3 +237,25 @@ func (ti *TextInput) HandleKey() { func (ti *TextInput) Text() string { return ti.input } + +type NumberInput struct { + TextInput + n int +} + +func NewNumberInput(x, y int, height, width int, number int) *NumberInput { + ni := &NumberInput{ + n: 0, + } + ni.InitTextInput(x, y, width, height, strconv.Itoa(number)) + return ni +} + +func (ni *NumberInput) Add(x int) { + ni.n = ni.n + x + ni.SetInput(strconv.Itoa(ni.n)) +} + +func (ni *NumberInput) Number() int { + return ni.n +} |
