holy shit components are rendering whaaaaaaaaaaaaaaaat

This commit was merged in pull request #4.
This commit is contained in:
2025-08-28 14:32:23 -04:00
parent 573396054f
commit 4829fbb5c7
14 changed files with 511 additions and 280 deletions

View File

@@ -1,68 +1,29 @@
package elements
import (
"git.vezzani.net/ben/games/common/elements/v1/mouse"
"github.com/hajimehoshi/ebiten/v2"
)
type ElementFunc func(Dimensions) Element
type MouseState struct {
X, Y int32
LeftDown, RightDown bool
LeftChanged, RightChanged bool
}
type ElementFunc func(Bounds) Element
type Clickable interface {
HandleClick(s MouseState) error
}
type Mouseable interface {
HandleMouseEnter(s MouseState) error
HandleMouseLeave(s MouseState) error
HandleMouseMove(s MouseState) error
HandleMouseDown(s MouseState) error
HandleMouseUp(s MouseState) error
}
type Element interface {
Draw(image *ebiten.Image, anchorX, anchorY float64) (w, h float64)
HandleMouseEvent(s mouse.State) bool
Draw(image *ebiten.Image) (w, h float64)
}
type Dimensions struct {
zx, zy float64
wx, wy float64
type Point struct {
X, Y float64
}
type mouseHandler struct {
mouseState MouseState
prevMouseState MouseState
}
func (b *mouseHandler) HandleMouseEnter(s MouseState) error {
b.mouseState = s
return nil
}
func (b *mouseHandler) HandleMouseLeave(s MouseState) error {
b.prevMouseState = b.mouseState
b.mouseState = MouseState{}
return nil
}
func (b *mouseHandler) HandleMouseMove(s MouseState) error {
b.prevMouseState = b.mouseState
b.mouseState = s
return nil
}
func (b *mouseHandler) HandleMouseDown(s MouseState) error {
b.prevMouseState = b.mouseState
b.mouseState = s
return nil
}
func (b *mouseHandler) HandleMouseUp(s MouseState) error {
b.prevMouseState = b.mouseState
b.mouseState = s
return nil
type Bounds struct {
Min Point
Width, Height float64
}