ux stuff
This commit is contained in:
8
common/control/v1/mouse.go
Normal file
8
common/control/v1/mouse.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package control
|
||||
|
||||
const (
|
||||
MouseLeft MouseButton = iota
|
||||
MouseRight
|
||||
)
|
||||
|
||||
type MouseButton int
|
||||
23
common/elements/v1/block.go
Normal file
23
common/elements/v1/block.go
Normal 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) {
|
||||
|
||||
}
|
||||
65
common/elements/v1/button.go
Normal file
65
common/elements/v1/button.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"context"
|
||||
"image/color"
|
||||
|
||||
"github.com/ebitengine/gomobile/event/mouse"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"golang.org/x/image/font"
|
||||
)
|
||||
import "git.vezzani.net/ben/games/common/ux/v1"
|
||||
|
||||
type XAlign int
|
||||
type YAlign int
|
||||
|
||||
const (
|
||||
AlignCente XAlign = iota
|
||||
AlignLeft
|
||||
AlignRight
|
||||
)
|
||||
|
||||
const (
|
||||
AlignCenter YAlign = iota
|
||||
AlignTop
|
||||
AlignBottom
|
||||
)
|
||||
|
||||
type Button struct {
|
||||
Label string
|
||||
OnClick func() error
|
||||
OnRightClick func() error
|
||||
Style struct {
|
||||
XAlign XAlign
|
||||
YAlign YAlign
|
||||
Offset int
|
||||
Font *font.Face
|
||||
BackgroundColor color.Color
|
||||
}
|
||||
|
||||
down bool
|
||||
}
|
||||
|
||||
func (b *Button) HandleMouseMove(ctx context.Context, s MouseState) error {
|
||||
|
||||
}
|
||||
|
||||
func (b *Button) HandleMouseDown(_ context.Context, _ MouseState) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Button) HandleMouseUp(ctx context.Context, s MouseState) error {
|
||||
if
|
||||
}
|
||||
|
||||
func (b *Button) getFont() font.Face {
|
||||
if b.Style.Font == nil {
|
||||
return ux.FontFace
|
||||
}
|
||||
|
||||
return *b.Style.Font
|
||||
}
|
||||
|
||||
func (b *Button) Draw(ctx context.Context, image *ebiten.Image) error {
|
||||
|
||||
}
|
||||
42
common/elements/v1/element.go
Normal file
42
common/elements/v1/element.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type MouseState struct {
|
||||
X, Y int32
|
||||
LeftDown, RightDown bool
|
||||
}
|
||||
|
||||
const (
|
||||
ParentKey = "parent_element"
|
||||
ZeroKey = "zero"
|
||||
)
|
||||
|
||||
type Mouseable interface {
|
||||
HandleMouseMove(ctx context.Context, s MouseState) error
|
||||
HandleMouseDown(ctx context.Context, s MouseState) error
|
||||
HandleMouseUp(ctx context.Context, s MouseState) error
|
||||
}
|
||||
|
||||
type Element interface {
|
||||
Draw(ctx context.Context, image *ebiten.Image) error
|
||||
Size() (w, h int32)
|
||||
}
|
||||
|
||||
func GetZero(ctx context.Context) (x, y int32) {
|
||||
if v, ok := ctx.Value(ZeroKey).([2]int32); ok {
|
||||
return v[0], v[1]
|
||||
}
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
func GetParent(ctx context.Context) Element {
|
||||
if e, ok := ctx.Value(ParentKey).(Element); ok {
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
1
common/elements/v1/menu.go
Normal file
1
common/elements/v1/menu.go
Normal file
@@ -0,0 +1 @@
|
||||
package elements
|
||||
1
common/elements/v1/table.go
Normal file
1
common/elements/v1/table.go
Normal file
@@ -0,0 +1 @@
|
||||
package elements
|
||||
13
common/ux/v1/ux.go
Normal file
13
common/ux/v1/ux.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package ux
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/basicfont"
|
||||
)
|
||||
|
||||
var (
|
||||
FontFace font.Face = basicfont.Face7x13
|
||||
BackgroundColor color.Color = color.White
|
||||
)
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user