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

@@ -10,44 +10,31 @@ import (
"github.com/hajimehoshi/ebiten/v2/vector"
)
func New(ops ...OptFunc) elements.InitFunc {
return func() elements.Element {
b := Block{}
for i := range ops {
ops[i](&b)
}
return &b
func New(ops ...OptFunc) elements.Element {
b := Block{}
for i := range ops {
ops[i](&b)
}
return &b
}
type Block struct {
anchor elements.Point
elements.Core
backgroundColor *color.Color
mouse.NopHandler
width, height int
name string
}
func (b *Block) SetAnchor(a elements.Point) {
d := b.anchor.Delta(a)
for i := range b.Children() {
b.Children()[i].SetAnchor(b.Children()[i].Anchor().Add(d))
}
b.anchor = a
}
func (b *Block) Bounds() elements.Bounds {
return elements.Bounds{
Min: b.anchor,
Min: b.Anchor(),
Width: b.width,
Height: b.height,
}
}
func (b *Block) Anchor() elements.Point {
return b.anchor
}
func (b *Block) Size() (w, h int) {
return b.width, b.height
}
@@ -57,8 +44,8 @@ func (b *Block) Draw(image *ebiten.Image) {
if b.backgroundColor != nil {
vector.DrawFilledRect(
image,
float32(b.anchor.X),
float32(b.anchor.Y),
float32(b.Anchor().X),
float32(b.Anchor().Y),
float32(bnd.Width),
float32(bnd.Height),
*b.backgroundColor,
@@ -67,7 +54,3 @@ func (b *Block) Draw(image *ebiten.Image) {
}
return
}
func (b *Block) Children() []elements.Element {
return nil
}