okay new ux idea

This commit is contained in:
2025-08-27 23:22:39 -04:00
parent 8b1bfc8a01
commit de709f912d
8 changed files with 99 additions and 189 deletions

View File

@@ -1,61 +1,28 @@
package elements
import (
"context"
"image/color"
"git.vezzani.net/ben/games/common/ux/v1"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
"golang.org/x/image/font"
)
type Block struct {
Label string
Style struct {
Width float32
Height float32
XAlign XAlign
YAlign YAlign
Offset int
Font *font.Face
BackgroundColor *color.Color
}
}
type BlockOption func(*block)
func (b *Block) backgroundColor() color.Color {
var c *color.Color
if b.Style.BackgroundColor != nil {
c = b.Style.BackgroundColor
} else {
c = &ux.BackgroundColor
}
return *c
}
func (b *Block) size(ctx context.Context) (x, y float32) {
x = b.Style.Width
y = b.Style.Height
if x == 0 || y == 0 {
px, py := GetContainerSize(ctx)
if x == 0 {
x = px
}
if y == 0 {
y = py
func Block(ops ...BlockOption) ElementFunc {
return func(d Dimensions) Element {
b := block{}
for i := range ops {
ops[i](&b)
}
return &b
}
return
}
func (b *Block) Draw(ctx context.Context, image *ebiten.Image) error {
xz, yz := GetZero(ctx)
w, h := b.size(ctx)
vector.StrokeRect(image, xz, yz, w, h, 1, b.backgroundColor(), true)
return nil
type block struct {
width float64
height float64
xAlign xAlign
yAlign yAlign
}
func (b block) Draw(image *ebiten.Image, anchorX, anchorY float64) (w, h float64) {
return b.width, b.height
}