diff options
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 +} |
