Skip to content

Commit 6d80aaf

Browse files
authored
Add example Go file for DebugUI usage
Added an example Go file demonstrating the usage of DebugUI.
1 parent 302192e commit 6d80aaf

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,57 @@ DebugUI is a UI toolkit for Ebitengine applications, primarily intended for debu
88

99
DebugUI is based on [Microui](https://github.com/rxi/microui). The original Microui was developed by [@rxi](https://github.com/rxi/microui). The original Go port was developed by [@zeozeozeo](https://github.com/zeozeozeo) and [@Zyko0](https://github.com/Zyko0).
1010

11+
## Example go file
12+
```go
13+
package main
14+
15+
import (
16+
"fmt"
17+
"image"
18+
19+
"github.com/ebitengine/debugui"
20+
"github.com/hajimehoshi/ebiten/v2"
21+
)
22+
23+
type Game struct {
24+
debugui debugui.DebugUI // Place a debugui instance on your Game
25+
}
26+
27+
func (g *Game) Update() error {
28+
if _, err := g.debugui.Update(func(ctx *debugui.Context) error {
29+
ctx.Window("Debugui Window", image.Rect(0, 0, 640, 400), func(layout debugui.ContainerLayout) {
30+
// Place all your widgets inside a ctx.Window
31+
ctx.Text("Some text")
32+
33+
// If you ever need to make loop to make widgets, use ctx.Loop
34+
loopCount := 10
35+
ctx.Loop(loopCount, func(index int) {
36+
ctx.Text(fmt.Sprintf("Index value is %d", index))
37+
})
38+
})
39+
return nil
40+
}); err != nil {
41+
return err
42+
}
43+
return nil
44+
}
45+
46+
func (g *Game) Draw(screen *ebiten.Image) {
47+
g.debugui.Draw(screen) // Draw debugui at the end
48+
}
49+
50+
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
51+
return outsideWidth, outsideHeight
52+
}
53+
54+
func main() {
55+
game := &Game{}
56+
if err := ebiten.RunGame(game); err != nil {
57+
panic(err)
58+
}
59+
}
60+
```
61+
1162
## License
1263

1364
DebugUI for Ebitengine is licensed under Apache license version 2.0. See [LICENSE](LICENSE) file.

0 commit comments

Comments
 (0)