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(d elements.Dimensions) elements.Element { s := Stack{ Block: blocks.Block{InheritedDimensions: d}, } 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) (w, h float64) { s.Block.Draw(image) d := s.InheritedDimensions d.WX, d.WY = s.Block.Size() if s.horizontal { d.WX = d.WX / float64(len(s.children)) } else { d.WY = d.WY / float64(len(s.children)) } var offsetX, offsetY float64 for i := range s.children { offsetX, offsetY = s.children[i](d).Draw(image) if s.horizontal { d.ZX += offsetX } else { d.ZY += offsetY } } return s.Block.Size() }