cleaning up the component system just a bit more...

This commit is contained in:
2025-08-31 21:15:18 -04:00
parent e454d649a5
commit 5f47a811aa
9 changed files with 114 additions and 110 deletions

View File

@@ -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
}