This commit is contained in:
2025-08-18 14:57:01 -04:00
parent 627ca88732
commit 7d86137f2b
9 changed files with 111 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
package control
const (
MouseLeft MouseButton = iota
MouseRight
)
type MouseButton int

View File

@@ -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) {
}

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -0,0 +1 @@
package elements

View File

@@ -0,0 +1 @@
package elements

10
common/ux/v1/ux.go Normal file
View File

@@ -0,0 +1,10 @@
package ux
import (
"golang.org/x/image/font"
"golang.org/x/image/font/basicfont"
)
var (
FontFace font.Face = basicfont.Face7x13
)

View File

@@ -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")