package stacks import ( "git.vezzani.net/ben/games/common/elements/v1/core" "git.vezzani.net/ben/games/common/elements/v1/mouse" "github.com/hajimehoshi/ebiten/v2" ) func New(ops ...OptFunc) *Stack { s := Stack{} for op := range ops { ops[op](&s) } var cw, ch int anchor := s.Anchor() for _, c := range s.Children() { c.SetAnchor(anchor) cw, ch = c.Size() if s.horizontal { anchor.X += cw } else { anchor.Y += ch } } return &s } type Stack struct { core.Element mouse.NopHandler horizontal bool } func (s *Stack) Size() (w, h int) { var cw, ch int for _, c := range s.Children() { cw, ch = c.Size() if s.horizontal { w += cw if h < ch { h = ch } } else { h += ch if w < cw { w = cw } } } return } func (s *Stack) Draw(image *ebiten.Image) { for _, c := range s.Children() { c.Draw(image) } }