Skip to content

Commit b05260c

Browse files
committed
debugui: refactoring
1 parent 79781ed commit b05260c

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

control.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import (
99
"math"
1010
"os"
1111
"strconv"
12+
"strings"
1213
"unicode/utf8"
1314

1415
"github.com/hajimehoshi/ebiten/v2"
1516
"github.com/hajimehoshi/ebiten/v2/exp/textinput"
1617
"github.com/hajimehoshi/ebiten/v2/inpututil"
1718
)
1819

20+
const idSeparator = "\x00"
21+
1922
const (
2023
realFmt = "%.3g"
2124
sliderFmt = "%.2f"
@@ -152,7 +155,8 @@ func (c *Context) Label(text string) {
152155
})
153156
}
154157

155-
func (c *Context) button(label string, idStr string, opt option) (controlID, bool) {
158+
func (c *Context) button(label string, opt option) (controlID, bool) {
159+
label, idStr, _ := strings.Cut(label, idSeparator)
156160
id := c.idFromString(idStr)
157161
return id, c.control(id, opt, func(bounds image.Rectangle) Response {
158162
var res Response
@@ -372,7 +376,8 @@ func (c *Context) number(value *float64, step float64, digits int, opt option) b
372376
}) != 0
373377
}
374378

375-
func (c *Context) header(label string, idStr string, istreenode bool, opt option, f func()) {
379+
func (c *Context) header(label string, istreenode bool, opt option, f func()) {
380+
label, idStr, _ := strings.Cut(label, idSeparator)
376381
id := c.idFromString(idStr)
377382
_, toggled := c.toggledIDs[id]
378383
c.SetGridLayout([]int{-1}, nil)
@@ -427,8 +432,8 @@ func (c *Context) header(label string, idStr string, istreenode bool, opt option
427432
}
428433
}
429434

430-
func (c *Context) treeNode(label string, idStr string, opt option, f func()) {
431-
c.header(label, idStr, true, opt, func() {
435+
func (c *Context) treeNode(label string, opt option, f func()) {
436+
c.header(label, true, opt, func() {
432437
c.layout().indent += c.style.indent
433438
defer func() {
434439
c.layout().indent -= c.style.indent

export_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
package debugui
55

6-
import "strings"
7-
86
type ControlID = controlID
97

108
func (c *Context) ButtonID(label string) ControlID {
11-
label, idStr, _ := strings.Cut(label, idSeparator)
12-
id, _ := c.button(label, idStr, optionAlignCenter)
9+
id, _ := c.button(label, optionAlignCenter)
1310
return id
1411
}

widget.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ package debugui
55

66
import (
77
"image"
8-
"strings"
98
)
109

11-
const idSeparator = "\x00"
12-
1310
func (c *Context) Button(label string) bool {
14-
label, idStr, _ := strings.Cut(label, idSeparator)
15-
_, result := c.button(label, idStr, optionAlignCenter)
11+
_, result := c.button(label, optionAlignCenter)
1612
return result
1713
}
1814

@@ -33,13 +29,11 @@ func (c *Context) Header(label string, expanded bool, f func()) {
3329
if expanded {
3430
opt |= optionExpanded
3531
}
36-
label, idStr, _ := strings.Cut(label, idSeparator)
37-
c.header(label, idStr, false, opt, f)
32+
c.header(label, false, opt, f)
3833
}
3934

4035
func (c *Context) TreeNode(label string, f func()) {
41-
label, idStr, _ := strings.Cut(label, idSeparator)
42-
c.treeNode(label, idStr, 0, f)
36+
c.treeNode(label, 0, f)
4337
}
4438

4539
func (c *Context) Window(title string, rect image.Rectangle, f func(layout ContainerLayout)) {

0 commit comments

Comments
 (0)