okay giant ux refactor to hopefully make it cleaner

This commit is contained in:
2025-08-31 13:29:52 -04:00
parent 430259475b
commit dda0a83202
12 changed files with 214 additions and 198 deletions

View File

@@ -5,15 +5,14 @@ import (
"git.vezzani.net/ben/games/common/elements/v1"
"git.vezzani.net/ben/games/common/elements/v1/mouse"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)
func New(ops ...Option) elements.InitFunc {
return func(d elements.Bounds) elements.Element {
b := Block{
ContainerBounds: d,
}
func New(ops ...OptFunc) elements.InitFunc {
return func() elements.Element {
b := Block{}
for i := range ops {
ops[i](&b)
}
@@ -22,37 +21,53 @@ func New(ops ...Option) elements.InitFunc {
}
type Block struct {
ContainerBounds elements.Bounds
anchor elements.Point
backgroundColor *color.Color
mouse.NopHandler
width float64
height float64
name string
width, height int
name string
}
func (b *Block) Size() (w, h float64) {
w, h = b.ContainerBounds.Width, b.ContainerBounds.Height
if b.width != 0 {
w = b.width
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))
}
if b.height != 0 {
h = b.height
b.anchor = a
}
func (b *Block) Bounds() elements.Bounds {
return elements.Bounds{
Min: b.anchor,
Width: b.width,
Height: b.height,
}
return
}
func (b *Block) Anchor() elements.Point {
return b.anchor
}
func (b *Block) Size() (w, h int) {
return b.width, b.height
}
func (b *Block) Draw(image *ebiten.Image) {
w, h := b.Size()
bnd := b.Bounds()
if b.backgroundColor != nil {
vector.DrawFilledRect(
image,
float32(b.ContainerBounds.Min.X),
float32(b.ContainerBounds.Min.Y),
float32(w),
float32(h),
float32(b.anchor.X),
float32(b.anchor.Y),
float32(bnd.Width),
float32(bnd.Height),
*b.backgroundColor,
true,
)
}
return
}
func (b *Block) Children() []elements.Element {
return nil
}