holy shit components are rendering whaaaaaaaaaaaaaaaat

This commit is contained in:
2025-08-28 14:32:23 -04:00
parent 573396054f
commit 12a9a5017a
12 changed files with 357 additions and 267 deletions

View File

@@ -0,0 +1,11 @@
package stacks
import "git.vezzani.net/ben/games/common/elements/v1/blocks"
type Option func(*Stack)
func BlockOpt(o blocks.Option) Option {
return func(s *Stack) {
o(&s.Block)
}
}

View File

@@ -0,0 +1,48 @@
package stacks
import (
"git.vezzani.net/ben/games/common/elements/v1"
"git.vezzani.net/ben/games/common/elements/v1/blocks"
"git.vezzani.net/ben/games/common/elements/v1/mouse"
"github.com/hajimehoshi/ebiten/v2"
)
func New(ops ...Option) elements.ElementFunc {
return func(parentDimensions elements.Dimensions) elements.Element {
s := Stack{}
for op := range ops {
ops[op](&s)
}
return &s
}
}
type Stack struct {
blocks.Block
mouse.NopHandler
horizontal bool
children []elements.ElementFunc
}
func (s *Stack) Draw(image *ebiten.Image, anchorX, anchorY float64) (w, h float64) {
s.Block.Draw(image, anchorX, anchorY)
var offsetX, offsetY float64
originalX, originalY := anchorX, anchorY
d := elements.Dimensions{
ZX: originalX,
ZY: originalY,
}
d.WX, d.WY = s.Block.Size()
for i := range s.children {
offsetX, offsetY = s.children[i](d).Draw(image, anchorX, anchorY)
if s.horizontal {
anchorX += offsetX
} else {
anchorY += offsetY
}
}
return anchorX - originalX, anchorY - originalY
}