Skip to content

Commit 4537dcb

Browse files
committed
debugui: change the button layout for number fields
Updates #33
1 parent afc0ffe commit 4537dcb

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

draw.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const (
5151
iconCheck
5252
iconCollapsed
5353
iconExpanded
54+
iconDown
55+
iconUp
5456
)
5557

5658
var (
@@ -80,6 +82,10 @@ func iconImage(icon icon) *ebiten.Image {
8082
name = "collapsed.png"
8183
case iconExpanded:
8284
name = "expanded.png"
85+
case iconDown:
86+
name = "down.png"
87+
case iconUp:
88+
name = "up.png"
8389
default:
8490
return nil
8591
}

icon/down.png

91 Bytes
Loading

icon/up.png

87 Bytes
Loading

textfield.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (c *Context) numberField(value *int, step int, id widgetID, opt option) (Ev
160160
var e EventHandler
161161
var err error
162162
c.GridCell(func(bounds image.Rectangle) {
163-
c.SetGridLayout([]int{-1, c.style().thumbSize, c.style().thumbSize}, nil)
163+
c.SetGridLayout([]int{-1, lineHeight()}, nil)
164164
// handle normal mode
165165
e, err = c.widget(id, opt, nil, func(bounds image.Rectangle, wasFocused bool) EventHandler {
166166
var e EventHandler
@@ -176,13 +176,16 @@ func (c *Context) numberField(value *int, step int, id widgetID, opt option) (Ev
176176
text := fmt.Sprintf("%d", *value)
177177
c.drawWidgetText(text, bounds, colorText, opt)
178178
})
179-
c.Button("-").On(func() {
180-
*value -= step
181-
e = &eventHandler{}
182-
})
183-
c.Button("+").On(func() {
184-
*value += step
185-
e = &eventHandler{}
179+
c.GridCell(func(bounds image.Rectangle) {
180+
c.SetGridLayout(nil, []int{(c.style().defaultHeight - c.style().spacing) / 2})
181+
c.iconButton(iconUp).On(func() {
182+
*value += step
183+
e = &eventHandler{}
184+
})
185+
c.iconButton(iconDown).On(func() {
186+
*value -= step
187+
e = &eventHandler{}
188+
})
186189
})
187190
})
188191

@@ -206,7 +209,7 @@ func (c *Context) numberFieldF(value *float64, step float64, digits int, id widg
206209
var e EventHandler
207210
var err error
208211
c.GridCell(func(bounds image.Rectangle) {
209-
c.SetGridLayout([]int{-1, c.style().thumbSize, c.style().thumbSize}, nil)
212+
c.SetGridLayout([]int{-1, lineHeight()}, nil)
210213
// handle normal mode
211214
e, err = c.widget(id, opt, nil, func(bounds image.Rectangle, wasFocused bool) EventHandler {
212215
var e EventHandler
@@ -222,13 +225,16 @@ func (c *Context) numberFieldF(value *float64, step float64, digits int, id widg
222225
text := formatNumber(*value, digits)
223226
c.drawWidgetText(text, bounds, colorText, opt)
224227
})
225-
c.Button("-").On(func() {
226-
*value -= step
227-
e = &eventHandler{}
228-
})
229-
c.Button("+").On(func() {
230-
*value += step
231-
e = &eventHandler{}
228+
c.GridCell(func(bounds image.Rectangle) {
229+
c.SetGridLayout(nil, []int{(c.style().defaultHeight - c.style().spacing) / 2})
230+
c.iconButton(iconUp).On(func() {
231+
*value += step
232+
e = &eventHandler{}
233+
})
234+
c.iconButton(iconDown).On(func() {
235+
*value -= step
236+
e = &eventHandler{}
237+
})
232238
})
233239
})
234240
if err != nil {

0 commit comments

Comments
 (0)