Skip to content

Commit e605b2c

Browse files
authored
all: add an example to the README (#46)
Added an example Go file demonstrating the usage of DebugUI.
1 parent 302192e commit e605b2c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,59 @@ 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+
const loopCount = 10
24+
25+
type Game struct {
26+
debugui debugui.DebugUI // Place a debugui instance on your Game
27+
}
28+
29+
func (g *Game) Update() error {
30+
if _, err := g.debugui.Update(func(ctx *debugui.Context) error {
31+
ctx.Window("Debugui Window", image.Rect(0, 0, 320, 240), func(layout debugui.ContainerLayout) {
32+
// Place all your widgets inside a ctx.Window
33+
ctx.Text("Some text")
34+
35+
// If you ever need to make a loop to make widgets, use ctx.Loop
36+
37+
ctx.Loop(loopCount, func(index int) {
38+
ctx.Text(fmt.Sprintf("Index value is %d", index))
39+
})
40+
})
41+
return nil
42+
}); err != nil {
43+
return err
44+
}
45+
return nil
46+
}
47+
48+
func (g *Game) Draw(screen *ebiten.Image) {
49+
g.debugui.Draw(screen) // Draw debugui at the end
50+
}
51+
52+
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
53+
return outsideWidth, outsideHeight
54+
}
55+
56+
func main() {
57+
game := &Game{}
58+
if err := ebiten.RunGame(game); err != nil {
59+
panic(err)
60+
}
61+
}
62+
```
63+
1164
## License
1265

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

0 commit comments

Comments
 (0)