okay new ux idea
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user