From 7d86137f2beaa71b3caf035d9c895e1f49c05b6f Mon Sep 17 00:00:00 2001 From: Ben Vezzani Date: Mon, 18 Aug 2025 14:57:01 -0400 Subject: [PATCH] ux stuff --- common/control/v1/mouse.go | 8 ++++++ common/elements/v1/block.go | 23 +++++++++++++++++ common/elements/v1/button.go | 32 +++++++++++++++++++++++ common/elements/v1/element.go | 34 +++++++++++++++++++++++++ common/elements/v1/menu.go | 1 + common/elements/v1/table.go | 1 + common/ux/v1/ux.go | 10 ++++++++ games/minesweeper/{ => v1}/game/game.go | 0 games/minesweeper/{ => v1}/main.go | 4 +-- 9 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 common/control/v1/mouse.go create mode 100644 common/elements/v1/block.go create mode 100644 common/elements/v1/button.go create mode 100644 common/elements/v1/element.go create mode 100644 common/elements/v1/menu.go create mode 100644 common/elements/v1/table.go create mode 100644 common/ux/v1/ux.go rename games/minesweeper/{ => v1}/game/game.go (100%) rename games/minesweeper/{ => v1}/main.go (74%) diff --git a/common/control/v1/mouse.go b/common/control/v1/mouse.go new file mode 100644 index 0000000..73e5121 --- /dev/null +++ b/common/control/v1/mouse.go @@ -0,0 +1,8 @@ +package control + +const ( + MouseLeft MouseButton = iota + MouseRight +) + +type MouseButton int diff --git a/common/elements/v1/block.go b/common/elements/v1/block.go new file mode 100644 index 0000000..54f118e --- /dev/null +++ b/common/elements/v1/block.go @@ -0,0 +1,23 @@ +package elements + +import ( + "context" + + "github.com/hajimehoshi/ebiten/v2" +) + +func NewBlock(inline bool) *Block { + +} + +type Block struct { + inline bool +} + +func (b *Block) Draw(ctx context.Context, image *ebiten.Image) error { + +} + +func (b *Block) OnClick(ctx context.Context, click *ClickEvent) { + +} diff --git a/common/elements/v1/button.go b/common/elements/v1/button.go new file mode 100644 index 0000000..79098d0 --- /dev/null +++ b/common/elements/v1/button.go @@ -0,0 +1,32 @@ +package elements + +import ( + "context" + + "github.com/hajimehoshi/ebiten/v2" + "golang.org/x/image/font" +) +import "git.vezzani.net/ben/games/common/ux/v1" + +type Button struct { + Label string + LabelPosition + Font *font.Face + OnClick func(click *ClickEvent) error +} + +func (b *Button) getFont() font.Face { + if b.Font == nil { + return ux.FontFace + } + + return *b.Font +} + +func (b *Button) Draw(ctx context.Context, image *ebiten.Image) error { + +} + +func (b *Button) HandleClick(ctx context.Context, clickEvent *ClickEvent) error { + return b.OnClick(click) +} diff --git a/common/elements/v1/element.go b/common/elements/v1/element.go new file mode 100644 index 0000000..f07cb59 --- /dev/null +++ b/common/elements/v1/element.go @@ -0,0 +1,34 @@ +package elements + +import ( + "context" + + "git.vezzani.net/ben/games/common/control/v1" + + "github.com/hajimehoshi/ebiten/v2" +) + +type ClickEvent struct { + X, Y int + Button control.MouseButton +} + +const ( + ParentKey = "parent_element" +) + +type Clickable interface { + HandleClick(ctx context.Context, click *ClickEvent) error +} + +type Element interface { + Draw(ctx context.Context, image *ebiten.Image) error + Size() (w, h int32) +} + +func GetParent(ctx context.Context) Element { + if e, ok := ctx.Value(ParentKey).(Element); ok { + return e + } + return nil +} diff --git a/common/elements/v1/menu.go b/common/elements/v1/menu.go new file mode 100644 index 0000000..8a64ab6 --- /dev/null +++ b/common/elements/v1/menu.go @@ -0,0 +1 @@ +package elements diff --git a/common/elements/v1/table.go b/common/elements/v1/table.go new file mode 100644 index 0000000..8a64ab6 --- /dev/null +++ b/common/elements/v1/table.go @@ -0,0 +1 @@ +package elements diff --git a/common/ux/v1/ux.go b/common/ux/v1/ux.go new file mode 100644 index 0000000..fe2817d --- /dev/null +++ b/common/ux/v1/ux.go @@ -0,0 +1,10 @@ +package ux + +import ( + "golang.org/x/image/font" + "golang.org/x/image/font/basicfont" +) + +var ( + FontFace font.Face = basicfont.Face7x13 +) diff --git a/games/minesweeper/game/game.go b/games/minesweeper/v1/game/game.go similarity index 100% rename from games/minesweeper/game/game.go rename to games/minesweeper/v1/game/game.go diff --git a/games/minesweeper/main.go b/games/minesweeper/v1/main.go similarity index 74% rename from games/minesweeper/main.go rename to games/minesweeper/v1/main.go index b23f639..8a6b190 100644 --- a/games/minesweeper/main.go +++ b/games/minesweeper/v1/main.go @@ -3,12 +3,12 @@ package main import ( "log" - "git.vezzani.net/ben/games/games/minesweeper/game" + "git.vezzani.net/ben/games/games/minesweeper/v1/game" "github.com/hajimehoshi/ebiten/v2" ) func main() { - g := game.New(10, 10, 50) + g := game.New(10, 10, 15) w, h := g.Layout(0, 0) ebiten.SetWindowSize(w, h) ebiten.SetWindowTitle("Minesweeper")