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

@@ -1,40 +1,50 @@
package main
import (
"image/color"
"git.vezzani.net/ben/games/common/elements/v1"
"git.vezzani.net/ben/games/common/elements/v1/blocks"
"git.vezzani.net/ben/games/common/elements/v1/buttons"
"git.vezzani.net/ben/games/common/elements/v1/mouse"
"git.vezzani.net/ben/games/common/elements/v1/stacks"
"git.vezzani.net/ben/games/common/sprites/v1"
"github.com/hajimehoshi/ebiten/v2"
"golang.org/x/image/colornames"
)
var root = stacks.New(
stacks.Horizontal(),
stacks.BlockOpt(blocks.BackgroundColor(color.White)),
stacks.BlockOpt(blocks.Size(200, 200)),
stacks.BlockOpt(blocks.Name("parent")),
//stacks.BlockOpt(blocks.BackgroundColor(color.White)),
//stacks.BlockOpt(blocks.Name("parent")),
stacks.Children(
stacks.New(
stacks.BlockOpt(blocks.Name("left")),
//stacks.BlockOpt(blocks.Name("left")),
stacks.Children(
buttons.New(
buttons.BlockOpt(blocks.Size(100, 100)),
buttons.Label("hello"),
buttons.BlockOpt(blocks.BackgroundColor(colornames.Green)),
buttons.OnClick(func(ms mouse.State) {
println("green")
}),
),
blocks.New(blocks.BackgroundColor(colornames.Yellow)),
)),
blocks.New(
blocks.Size(100, 100),
blocks.BackgroundColor(colornames.Yellow),
),
),
),
stacks.New(
stacks.BlockOpt(blocks.Name("right")),
//stacks.BlockOpt(blocks.Name("right")),
stacks.Children(
blocks.New(blocks.BackgroundColor(colornames.Blue)),
blocks.New(blocks.BackgroundColor(colornames.Red)),
blocks.New(
blocks.Size(100, 100),
blocks.BackgroundColor(colornames.Blue),
),
blocks.New(
blocks.Size(100, 100),
blocks.BackgroundColor(colornames.Red),
),
),
),
),
@@ -61,13 +71,13 @@ func (e *editor) Draw(screen *ebiten.Image) {
}
func (e *editor) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
if e.bounds.Width != float64(outsideWidth) || e.bounds.Height != float64(outsideHeight) {
if e.bounds.Width != outsideWidth || e.bounds.Height != outsideHeight {
e.bounds = elements.Bounds{
Min: elements.Point{},
Width: float64(outsideWidth),
Height: float64(outsideHeight),
Width: outsideWidth,
Height: outsideHeight,
}
e.root = root(e.bounds)
e.root = root()
e.handleMouse = mouse.Handler(e.root)
}