Skip to content

Commit 1ca4371

Browse files
committed
debugui: refactoring: remove internal/caller
1 parent 67f0756 commit 1ca4371

File tree

7 files changed

+18
-35
lines changed

7 files changed

+18
-35
lines changed

control.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111

1212
"github.com/hajimehoshi/ebiten/v2"
1313
"github.com/hajimehoshi/ebiten/v2/inpututil"
14-
15-
"github.com/ebitengine/debugui/internal/caller"
1614
)
1715

1816
const idSeparator = "\x00"
@@ -94,7 +92,7 @@ func (c *Context) updateControl(id controlID, bounds image.Rectangle, opt option
9492
}
9593

9694
func (c *Context) Control(idStr string, f func(bounds image.Rectangle) bool) bool {
97-
pc := caller.Caller()
95+
pc := caller()
9896
var res bool
9997
c.wrapError(func() error {
10098
id := c.idFromCaller(pc, idStr)

export_test.go

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

44
package debugui
55

6-
import "github.com/ebitengine/debugui/internal/caller"
7-
86
type ControlID = controlID
97

108
const EmptyControlID = emptyControlID
119

1210
func (c *Context) ButtonID(label string) ControlID {
13-
pc := caller.Caller()
11+
pc := caller()
1412
var id controlID
1513
c.wrapError(func() error {
1614
var err error

helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"image"
10+
"runtime"
1011
"slices"
1112
"sort"
1213
"unsafe"
@@ -19,6 +20,15 @@ func clamp[T int | float64](x, a, b T) T {
1920
return min(b, max(a, x))
2021
}
2122

23+
// caller returns a program counter of the caller.
24+
func caller() uintptr {
25+
pc, _, _, ok := runtime.Caller(2)
26+
if !ok {
27+
return 0
28+
}
29+
return pc
30+
}
31+
2232
func (c *Context) idFromGlobalUniquePointer(pointer unsafe.Pointer) controlID {
2333
return controlID(fmt.Sprintf("!pointer:%p", pointer))
2434
}

internal/caller/caller.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

panel.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
package debugui
55

6-
import "github.com/ebitengine/debugui/internal/caller"
7-
86
func (c *Context) Panel(name string, f func(layout ContainerLayout)) {
9-
pc := caller.Caller()
7+
pc := caller()
108
c.wrapError(func() error {
119
if err := c.panel(name, 0, pc, f); err != nil {
1210
return err

widget.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
package debugui
55

6-
import "github.com/ebitengine/debugui/internal/caller"
7-
86
func (c *Context) Button(label string) bool {
9-
pc := caller.Caller()
7+
pc := caller()
108
var res bool
119
c.wrapError(func() error {
1210
var err error
@@ -33,7 +31,7 @@ func (c *Context) Slider(value *float64, lo, hi float64, step float64, digits in
3331
}
3432

3533
func (c *Context) Header(label string, expanded bool, f func()) {
36-
pc := caller.Caller()
34+
pc := caller()
3735
c.wrapError(func() error {
3836
var opt option
3937
if expanded {
@@ -50,7 +48,7 @@ func (c *Context) Header(label string, expanded bool, f func()) {
5048
}
5149

5250
func (c *Context) TreeNode(label string, f func()) {
53-
pc := caller.Caller()
51+
pc := caller()
5452
c.wrapError(func() error {
5553
if err := c.treeNode(label, 0, pc, f); err != nil {
5654
return err

window.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88

99
"github.com/hajimehoshi/ebiten/v2"
1010
"github.com/hajimehoshi/ebiten/v2/inpututil"
11-
12-
"github.com/ebitengine/debugui/internal/caller"
1311
)
1412

1513
func (c *Context) Window(title string, rect image.Rectangle, f func(layout ContainerLayout)) {
16-
pc := caller.Caller()
14+
pc := caller()
1715
c.wrapError(func() error {
1816
if err := c.window(title, rect, 0, pc, f); err != nil {
1917
return err
@@ -178,7 +176,7 @@ func (c *Context) ClosePopup(name string) {
178176
}
179177

180178
func (c *Context) Popup(name string, f func(layout ContainerLayout)) {
181-
pc := caller.Caller()
179+
pc := caller()
182180
c.wrapError(func() error {
183181
opt := optionPopup | optionAutoSize | optionNoResize | optionNoScroll | optionNoTitle | optionClosed
184182
if err := c.window(name, image.Rectangle{}, opt, pc, f); err != nil {

0 commit comments

Comments
 (0)