Skip to content

Commit 9ccbd47

Browse files
committed
debugui: refactoring: add (*Context).cursorPosition
1 parent 4b97f54 commit 9ccbd47

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

control.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (c *Context) inHoverRoot() bool {
4848
}
4949

5050
func (c *Context) mouseOver(bounds image.Rectangle) bool {
51-
p := image.Pt(ebiten.CursorPosition())
51+
p := c.cursorPosition()
5252
return p.In(bounds) && p.In(c.clipRect()) && c.inHoverRoot()
5353
}
5454

@@ -193,8 +193,7 @@ func (c *Context) slider(value *float64, low, high, step float64, digits int, op
193193
var res bool
194194
// handle input
195195
if c.focus == id && ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
196-
x, _ := ebiten.CursorPosition()
197-
v = low + float64(x-bounds.Min.X)*(high-low)/float64(bounds.Dx())
196+
v = low + float64(c.cursorPosition().X-bounds.Min.X)*(high-low)/float64(bounds.Dx())
198197
if step != 0 {
199198
v = math.Round(v/step) * step
200199
}

helpers.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ func (c *Context) begin() {
115115
}
116116

117117
func (c *Context) mouseDelta() image.Point {
118-
p := image.Pt(ebiten.CursorPosition())
119-
return p.Sub(c.lastMousePos)
118+
return c.cursorPosition().Sub(c.lastMousePos)
119+
}
120+
121+
func (c *Context) cursorPosition() image.Point {
122+
return image.Pt(ebiten.CursorPosition())
120123
}
121124

122125
func (c *Context) end() {
@@ -152,7 +155,7 @@ func (c *Context) end() {
152155
}
153156

154157
// reset input state
155-
c.lastMousePos = image.Pt(ebiten.CursorPosition())
158+
c.lastMousePos = c.cursorPosition()
156159

157160
// sort root containers by zindex
158161
sort.SliceStable(c.rootList, func(i, j int) bool {

window.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *Context) window(title string, bounds image.Rectangle, opt option, f fun
4141

4242
// set as hover root if the mouse is overlapping this container and it has a
4343
// higher zindex than the current hover root
44-
if image.Pt(ebiten.CursorPosition()).In(cnt.layout.Bounds) && (c.nextHoverRoot == nil || cnt.zIndex > c.nextHoverRoot.zIndex) {
44+
if c.cursorPosition().In(cnt.layout.Bounds) && (c.nextHoverRoot == nil || cnt.zIndex > c.nextHoverRoot.zIndex) {
4545
c.nextHoverRoot = cnt
4646
}
4747

@@ -138,7 +138,7 @@ func (c *Context) OpenPopup(name string) {
138138
c.nextHoverRoot = cnt
139139
c.hoverRoot = c.nextHoverRoot
140140
// position at mouse cursor, open and bring-to-front
141-
pt := image.Pt(ebiten.CursorPosition())
141+
pt := c.cursorPosition()
142142
cnt.layout.Bounds = image.Rectangle{
143143
Min: pt,
144144
Max: pt.Add(image.Pt(1, 1)),

0 commit comments

Comments
 (0)