Skip to content

Commit 6cf3b4b

Browse files
committed
debugui: rename TextBox -> TextField
1 parent a69d45b commit 6cf3b4b

4 files changed

Lines changed: 20 additions & 19 deletions

File tree

control.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,27 @@ func (c *Context) Checkbox(label string, state *bool) bool {
188188
})
189189
}
190190

191-
func (c *Context) textField(id controlID) *textinput.Field {
191+
func (c *Context) textInputTextField(id controlID) *textinput.Field {
192192
if id == 0 {
193193
return nil
194194
}
195-
if _, ok := c.textFields[id]; !ok {
196-
if c.textFields == nil {
197-
c.textFields = make(map[controlID]*textinput.Field)
195+
if _, ok := c.textInputTextFields[id]; !ok {
196+
if c.textInputTextFields == nil {
197+
c.textInputTextFields = make(map[controlID]*textinput.Field)
198198
}
199-
c.textFields[id] = &textinput.Field{}
199+
// TODO: Remove unused fields.
200+
c.textInputTextFields[id] = &textinput.Field{}
200201
}
201-
return c.textFields[id]
202+
return c.textInputTextFields[id]
202203
}
203204

204-
func (c *Context) textBoxRaw(buf *string, id controlID, opt option) bool {
205+
func (c *Context) textFieldRaw(buf *string, id controlID, opt option) bool {
205206
return c.control(id, opt|optionHoldFocus, func(bounds image.Rectangle) bool {
206207
var res bool
207208

208209
if c.focus == id {
209210
// handle text input
210-
f := c.textField(id)
211+
f := c.textInputTextField(id)
211212
f.Focus()
212213
x := bounds.Min.X + c.style.padding + textWidth(*buf)
213214
y := bounds.Min.Y + lineHeight()
@@ -236,7 +237,7 @@ func (c *Context) textBoxRaw(buf *string, id controlID, opt option) bool {
236237
}
237238
}
238239
} else {
239-
f := c.textField(id)
240+
f := c.textInputTextField(id)
240241
if *buf != f.TextForRendering() {
241242
f.SetTextAndSelection(*buf, len(*buf), len(*buf))
242243
}
@@ -262,14 +263,14 @@ func (c *Context) textBoxRaw(buf *string, id controlID, opt option) bool {
262263
})
263264
}
264265

265-
func (c *Context) numberTextBox(value *float64, id controlID) bool {
266+
func (c *Context) numberTextField(value *float64, id controlID) bool {
266267
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) && ebiten.IsKeyPressed(ebiten.KeyShift) &&
267268
c.hover == id {
268269
c.numberEdit = id
269270
c.numberEditBuf = fmt.Sprintf(realFmt, *value)
270271
}
271272
if c.numberEdit == id {
272-
res := c.textBoxRaw(&c.numberEditBuf, id, 0)
273+
res := c.textFieldRaw(&c.numberEditBuf, id, 0)
273274
if res || c.focus != id {
274275
nval, err := strconv.ParseFloat(c.numberEditBuf, 32)
275276
if err != nil {
@@ -283,9 +284,9 @@ func (c *Context) numberTextBox(value *float64, id controlID) bool {
283284
return false
284285
}
285286

286-
func (c *Context) textBox(buf *string, opt option) bool {
287+
func (c *Context) textField(buf *string, opt option) bool {
287288
id := c.idFromString(fmt.Sprintf("%p", buf))
288-
return c.textBoxRaw(buf, id, opt)
289+
return c.textFieldRaw(buf, id, opt)
289290
}
290291

291292
func formatNumber(v float64, digits int) string {
@@ -298,7 +299,7 @@ func (c *Context) slider(value *float64, low, high, step float64, digits int, op
298299
id := c.idFromString(fmt.Sprintf("%p", value))
299300

300301
// handle text input mode
301-
if c.numberTextBox(&v, id) {
302+
if c.numberTextField(&v, id) {
302303
return false
303304
}
304305

@@ -340,7 +341,7 @@ func (c *Context) number(value *float64, step float64, digits int, opt option) b
340341
last := *value
341342

342343
// handle text input mode
343-
if c.numberTextBox(value, id) {
344+
if c.numberTextField(value, id) {
344345
return false
345346
}
346347

example/ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (g *Game) logWindow(ctx *debugui.Context) {
162162
// input textbox + submit button
163163
var submitted bool
164164
ctx.SetGridLayout([]int{-1, 70}, nil)
165-
if ctx.TextBox(&g.logSubmitBuf) {
165+
if ctx.TextField(&g.logSubmitBuf) {
166166
ctx.SetFocus()
167167
submitted = true
168168
}

type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ type Context struct {
6969

7070
lastMousePos image.Point
7171

72-
textFields map[controlID]*textinput.Field
72+
textInputTextFields map[controlID]*textinput.Field
7373
}

widget.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func (c *Context) Button(label string) bool {
1212
return result
1313
}
1414

15-
func (c *Context) TextBox(buf *string) bool {
16-
return c.textBox(buf, 0)
15+
func (c *Context) TextField(buf *string) bool {
16+
return c.textField(buf, 0)
1717
}
1818

1919
func (c *Context) Slider(value *float64, lo, hi float64, step float64, digits int) bool {

0 commit comments

Comments
 (0)