Skip to content

Commit 60993d6

Browse files
committed
debugui: add icon buttons
1 parent 35cf89b commit 60993d6

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

button.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ func (c *Context) Button(text string) EventHandler {
1717
pc := caller()
1818
id := c.idFromCaller(pc)
1919
return c.wrapEventHandlerAndError(func() (EventHandler, error) {
20-
return c.button(text, optionAlignCenter, id)
20+
return c.button(text, iconNone, optionAlignCenter, id)
2121
})
2222
}
2323

24-
func (c *Context) button(text string, opt option, id widgetID) (EventHandler, error) {
24+
func (c *Context) iconButton(icon icon) EventHandler {
25+
pc := caller()
26+
id := c.idFromCaller(pc)
27+
return c.wrapEventHandlerAndError(func() (EventHandler, error) {
28+
return c.button("", icon, optionAlignCenter, id)
29+
})
30+
}
31+
32+
func (c *Context) button(text string, icon icon, opt option, id widgetID) (EventHandler, error) {
2533
return c.widget(id, opt, nil, func(bounds image.Rectangle, wasFocused bool) EventHandler {
2634
var e EventHandler
2735
if c.pointing.justPressed() && c.focus == id {
@@ -33,5 +41,8 @@ func (c *Context) button(text string, opt option, id widgetID) (EventHandler, er
3341
if len(text) > 0 {
3442
c.drawWidgetText(text, bounds, colorText, opt)
3543
}
44+
if icon != iconNone {
45+
c.drawIcon(icon, bounds, c.style().colors[colorText])
46+
}
3647
})
3748
}

draw.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func lineHeight() int {
4747
type icon int
4848

4949
const (
50-
iconCheck icon = 1 + iota
50+
iconNone icon = iota
51+
iconCheck
5152
iconCollapsed
5253
iconExpanded
5354
)
@@ -60,6 +61,10 @@ var (
6061
)
6162

6263
func iconImage(icon icon) *ebiten.Image {
64+
if icon == iconNone {
65+
return nil
66+
}
67+
6368
iconM.Lock()
6469
defer iconM.Unlock()
6570

0 commit comments

Comments
 (0)