holy shit components are rendering whaaaaaaaaaaaaaaaat
This commit is contained in:
11
common/elements/v1/stacks/options.go
Normal file
11
common/elements/v1/stacks/options.go
Normal 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)
|
||||
}
|
||||
}
|
||||
48
common/elements/v1/stacks/stack.go
Normal file
48
common/elements/v1/stacks/stack.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user