holy crap click handling works too
This commit was merged in pull request #5.
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
func New(ops ...Option) elements.ElementFunc {
|
||||
func New(ops ...Option) elements.InitFunc {
|
||||
return func(d elements.Bounds) elements.Element {
|
||||
s := Stack{
|
||||
Block: blocks.Block{ContainerBounds: d},
|
||||
@@ -16,6 +16,26 @@ func New(ops ...Option) elements.ElementFunc {
|
||||
for op := range ops {
|
||||
ops[op](&s)
|
||||
}
|
||||
|
||||
d.Width, d.Height = s.Block.Size()
|
||||
if s.horizontal {
|
||||
d.Width /= float64(len(s.childrenInit))
|
||||
} else {
|
||||
d.Height /= float64(len(s.childrenInit))
|
||||
}
|
||||
|
||||
s.Children = make([]elements.Element, len(s.childrenInit))
|
||||
var offsetX, offsetY float64
|
||||
for i := range s.childrenInit {
|
||||
s.Children[i] = s.childrenInit[i](d)
|
||||
offsetX, offsetY = s.Children[i].Size()
|
||||
if s.horizontal {
|
||||
d.Min.X += offsetX
|
||||
} else {
|
||||
d.Min.Y += offsetY
|
||||
}
|
||||
}
|
||||
|
||||
return &s
|
||||
}
|
||||
}
|
||||
@@ -23,29 +43,19 @@ func New(ops ...Option) elements.ElementFunc {
|
||||
type Stack struct {
|
||||
blocks.Block
|
||||
mouse.NopHandler
|
||||
horizontal bool
|
||||
children []elements.ElementFunc
|
||||
horizontal bool
|
||||
childrenInit []elements.InitFunc
|
||||
Children []elements.Element
|
||||
}
|
||||
|
||||
func (s *Stack) Draw(image *ebiten.Image) (w, h float64) {
|
||||
func (s *Stack) Draw(image *ebiten.Image) {
|
||||
s.Block.Draw(image)
|
||||
|
||||
d := s.ContainerBounds
|
||||
d.Width, d.Height = s.Block.Size()
|
||||
if s.horizontal {
|
||||
d.Width /= float64(len(s.children))
|
||||
} else {
|
||||
d.Height /= float64(len(s.children))
|
||||
for i := range s.Children {
|
||||
s.Children[i].Draw(image)
|
||||
}
|
||||
|
||||
var offsetX, offsetY float64
|
||||
for i := range s.children {
|
||||
offsetX, offsetY = s.children[i](d).Draw(image)
|
||||
if s.horizontal {
|
||||
d.Min.X += offsetX
|
||||
} else {
|
||||
d.Min.Y += offsetY
|
||||
}
|
||||
}
|
||||
return s.Block.Size()
|
||||
}
|
||||
|
||||
func (s *Stack) GetChildren() []elements.Element {
|
||||
return s.Children
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user