okay new ux idea

This commit is contained in:
2025-08-27 23:22:39 -04:00
parent 8b1bfc8a01
commit 573396054f
8 changed files with 134 additions and 210 deletions

View File

@@ -1,60 +1,36 @@
package elements
import (
"context"
"github.com/hajimehoshi/ebiten/v2"
)
type ElementFunc func(Dimensions) Element
type MouseState struct {
X, Y int32
LeftDown, RightDown bool
LeftChanged, RightChanged bool
}
const (
ContainerSizeKey = "container_size"
ZeroKey = "zero"
)
type Clickable interface {
Element
HandleClick(ctx context.Context, s MouseState) error
HandleClick(s MouseState) error
}
type Mouseable interface {
Element
HandleMouseEnter(ctx context.Context, s MouseState) error
HandleMouseLeave(ctx context.Context, s MouseState) error
HandleMouseMove(ctx context.Context, s MouseState) error
HandleMouseDown(ctx context.Context, s MouseState) error
HandleMouseUp(ctx context.Context, s MouseState) error
HandleMouseEnter(s MouseState) error
HandleMouseLeave(s MouseState) error
HandleMouseMove(s MouseState) error
HandleMouseDown(s MouseState) error
HandleMouseUp(s MouseState) error
}
type Element interface {
Draw(ctx context.Context, image *ebiten.Image) error
Draw(image *ebiten.Image, anchorX, anchorY float64) (w, h float64)
}
func SetZero(ctx context.Context, x, y float32) context.Context {
return context.WithValue(ctx, ZeroKey, [2]float32{x, y})
}
func SetContainerSize(ctx context.Context, w, h float32) context.Context {
return context.WithValue(ctx, ContainerSizeKey, [2]float32{w, h})
}
func GetZero(ctx context.Context) (x, y float32) {
if v, ok := ctx.Value(ZeroKey).([2]float32); ok {
return v[0], v[1]
}
return 0, 0
}
func GetContainerSize(ctx context.Context) (w, h float32) {
if s, ok := ctx.Value(ContainerSizeKey).([2]float32); ok {
return s[0], s[1]
}
return 0, 0
type Dimensions struct {
zx, zy float64
wx, wy float64
}
type mouseHandler struct {