Skip to content

Commit cb9034a

Browse files
committed
debugui: refactoring
1 parent fb64824 commit cb9034a

File tree

5 files changed

+76
-79
lines changed

5 files changed

+76
-79
lines changed

window.go renamed to container.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ import (
1010
"github.com/hajimehoshi/ebiten/v2/inpututil"
1111
)
1212

13+
type container struct {
14+
layout ContainerLayout
15+
headIdx int
16+
tailIdx int
17+
zIndex int
18+
open bool
19+
collapsed bool
20+
}
21+
22+
// ContainerLayout represents the layout of a container control.
23+
type ContainerLayout struct {
24+
// Bounds is the bounds of the control.
25+
Bounds image.Rectangle
26+
27+
// BodyBounds is the bounds of the body area of the container.
28+
BodyBounds image.Rectangle
29+
30+
// ContentSize is the size of the content.
31+
// ContentSize can be larger than Bounds or BodyBounds. In this case, the control should be scrollable.
32+
ContentSize image.Point
33+
34+
// ScrollOffset is the offset of the scroll.
35+
ScrollOffset image.Point
36+
}
37+
1338
func (c *Context) Window(title string, rect image.Rectangle, f func(layout ContainerLayout)) {
1439
pc := caller()
1540
c.wrapError(func() error {

context.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
3+
4+
package debugui
5+
6+
import (
7+
"image"
8+
9+
"github.com/hajimehoshi/ebiten/v2/exp/textinput"
10+
)
11+
12+
type Context struct {
13+
scaleMinus1 int
14+
hover controlID
15+
focus controlID
16+
lastID controlID
17+
lastZIndex int
18+
keepFocus bool
19+
tick int
20+
hoverRoot *container
21+
nextHoverRoot *container
22+
scrollTarget *container
23+
numberEditBuf string
24+
numberEdit controlID
25+
26+
commandList []*command
27+
rootList []*container
28+
containerStack []*container
29+
clipStack []image.Rectangle
30+
layoutStack []layout
31+
32+
idToContainer map[controlID]*container
33+
toggledIDs map[controlID]struct{}
34+
35+
lastMousePos image.Point
36+
37+
textInputTextFields map[controlID]*textinput.Field
38+
39+
err error
40+
}

control.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"github.com/hajimehoshi/ebiten/v2/inpututil"
1414
)
1515

16+
type controlID string
17+
18+
const emptyControlID controlID = ""
19+
1620
const idSeparator = "\x00"
1721

1822
type option int
@@ -265,7 +269,7 @@ func (c *Context) slider(value *float64, low, high, step float64, digits int, op
265269
return res, nil
266270
}
267271

268-
func (c *Context) header(label string, istreenode bool, opt option, callerPC uintptr, f func() error) error {
272+
func (c *Context) header(label string, isTreeNode bool, opt option, callerPC uintptr, f func() error) error {
269273
label, idStr, _ := strings.Cut(label, idSeparator)
270274
id := c.idFromCaller(callerPC, idStr)
271275
_, toggled := c.toggledIDs[id]
@@ -289,9 +293,7 @@ func (c *Context) header(label string, istreenode bool, opt option, callerPC uin
289293
c.toggledIDs[id] = struct{}{}
290294
}
291295
}
292-
293-
// draw
294-
if istreenode {
296+
if isTreeNode {
295297
if c.hover == id {
296298
c.drawFrame(bounds, ColorButtonHover)
297299
}

helpers.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func (c *Context) SetScroll(scroll image.Point) {
5858
}
5959

6060
func (c *Context) container(id controlID, opt option) *container {
61-
// try to get existing container from pool
6261
if container, ok := c.idToContainer[id]; ok {
6362
if !container.open && (^opt&optionClosed) == 0 {
6463
delete(c.idToContainer, id)
@@ -70,15 +69,15 @@ func (c *Context) container(id controlID, opt option) *container {
7069
return nil
7170
}
7271

73-
// container not found in pool: init new container
7472
if c.idToContainer == nil {
7573
c.idToContainer = map[controlID]*container{}
7674
}
77-
cnt := &container{}
75+
cnt := &container{
76+
headIdx: -1,
77+
tailIdx: -1,
78+
open: true,
79+
}
7880
c.idToContainer[id] = cnt
79-
cnt.headIdx = -1
80-
cnt.tailIdx = -1
81-
cnt.open = true
8281
c.bringToFront(cnt)
8382
return cnt
8483
}

type.go

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

0 commit comments

Comments
 (0)