diff --git a/README.md b/README.md index c5f497e..bd287a3 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,59 @@ DebugUI is a UI toolkit for Ebitengine applications, primarily intended for debu 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). +## Example go file +```go +package main + +import ( + "fmt" + "image" + + "github.com/ebitengine/debugui" + "github.com/hajimehoshi/ebiten/v2" +) + +const loopCount = 10 + +type Game struct { + debugui debugui.DebugUI // Place a debugui instance on your Game +} + +func (g *Game) Update() error { + if _, err := g.debugui.Update(func(ctx *debugui.Context) error { + ctx.Window("Debugui Window", image.Rect(0, 0, 320, 240), func(layout debugui.ContainerLayout) { + // Place all your widgets inside a ctx.Window + ctx.Text("Some text") + + // If you ever need to make a loop to make widgets, use ctx.Loop + + ctx.Loop(loopCount, func(index int) { + ctx.Text(fmt.Sprintf("Index value is %d", index)) + }) + }) + return nil + }); err != nil { + return err + } + return nil +} + +func (g *Game) Draw(screen *ebiten.Image) { + g.debugui.Draw(screen) // Draw debugui at the end +} + +func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { + return outsideWidth, outsideHeight +} + +func main() { + game := &Game{} + if err := ebiten.RunGame(game); err != nil { + panic(err) + } +} +``` + ## License DebugUI for Ebitengine is licensed under Apache license version 2.0. See [LICENSE](LICENSE) file.