cleaning up the component system just a bit more...
This commit is contained in:
@@ -4,8 +4,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type InitFunc func() Element
|
||||
|
||||
type Element interface {
|
||||
Draw(*ebiten.Image)
|
||||
SetAnchor(Point)
|
||||
@@ -40,3 +38,26 @@ type Bounds struct {
|
||||
func (b *Bounds) Contains(p Point) bool {
|
||||
return p.X >= b.Min.X && p.X <= b.Min.X+b.Width && p.Y >= b.Min.Y && p.Y <= b.Min.Y+b.Height
|
||||
}
|
||||
|
||||
type Core struct {
|
||||
anchor Point
|
||||
children []Element
|
||||
|
||||
name string // For debugging
|
||||
}
|
||||
|
||||
func (c *Core) Anchor() Point {
|
||||
return c.anchor
|
||||
}
|
||||
|
||||
func (c *Core) SetAnchor(a Point) {
|
||||
d := c.Anchor().Delta(a)
|
||||
for _, ch := range c.Children() {
|
||||
ch.SetAnchor(ch.Anchor().Add(d))
|
||||
}
|
||||
c.anchor = a
|
||||
}
|
||||
|
||||
func (c *Core) Children() []Element {
|
||||
return c.children
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user