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

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