From 7cd8f7be127e6a5ea563c20c0a0c93f8ede8e9ed Mon Sep 17 00:00:00 2001 From: Abdulmujeeb Raji Date: Sat, 22 Jul 2023 20:26:25 +0100 Subject: [PATCH] core: UI boilerplate --- go.sum | 1 - main.go | 31 ++++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/go.sum b/go.sum index 1364e7e..59a39b7 100644 --- a/go.sum +++ b/go.sum @@ -7,7 +7,6 @@ github.com/ebitenui/ebitenui v0.5.4/go.mod h1:2iyyjninLWNQLZ+pdV/eJ9vRnSs+I+HrzE github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/hajimehoshi/bitmapfont/v2 v2.2.3 h1:jmq/TMNj352V062Tr5e3hAoipkoxCbY1JWTzor0zNps= github.com/hajimehoshi/ebiten/v2 v2.5.5 h1:TJNoZsYJYUyFucwE56QRSgmZ+/cklUt1YrwpQVC5vjs= github.com/hajimehoshi/ebiten/v2 v2.5.5/go.mod h1:mnHSOVysTr/nUZrN1lBTRqhK4NG+T9NR3JsJP2rCppk= diff --git a/main.go b/main.go index 60612a9..6cd868c 100644 --- a/main.go +++ b/main.go @@ -3,18 +3,36 @@ package main import ( "log" + "github.com/ebitenui/ebitenui" + "github.com/ebitenui/ebitenui/image" + "github.com/ebitenui/ebitenui/widget" "github.com/hajimehoshi/ebiten/v2" - "github.com/hajimehoshi/ebiten/v2/ebitenutil" + img "image" + "image/color" ) -type Game struct{} +type Game struct{ + ui ebitenui.UI +} + +func uiInit() ebitenui.UI { + ui := ebitenui.UI{ + Container: widget.NewContainer(widget.ContainerOpts.Layout(widget.NewAnchorLayout())), + } + leftBar := widget.NewContainer(widget.ContainerOpts.BackgroundImage(image.NewNineSliceColor(color.White))) + leftBar.SetLocation(img.Rect(0, 0, 1, 1)) + ui.Container.AddChild(leftBar) + + return ui +} func (g *Game) Update() error { + g.ui.Update() return nil } func (g *Game) Draw(screen *ebiten.Image) { - ebitenutil.DebugPrint(screen, "Hello, World!") + g.ui.Draw(screen) } func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { @@ -23,8 +41,11 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeigh func main() { ebiten.SetWindowSize(640, 480) - ebiten.SetWindowTitle("Hello, World!") - if err := ebiten.RunGame(&Game{}); err != nil { + ebiten.SetWindowTitle("ambition: seriously prideful") + game := Game{ + ui: uiInit(), + } + if err := ebiten.RunGame(&game); err != nil { log.Fatal(err) } }