holy shit components are rendering whaaaaaaaaaaaaaaaat
This commit was merged in pull request #4.
This commit is contained in:
58
common/elements/v1/blocks/block.go
Normal file
58
common/elements/v1/blocks/block.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"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.ElementFunc {
|
||||
return func(d elements.Bounds) elements.Element {
|
||||
b := Block{
|
||||
ContainerBounds: d,
|
||||
}
|
||||
for i := range ops {
|
||||
ops[i](&b)
|
||||
}
|
||||
return &b
|
||||
}
|
||||
}
|
||||
|
||||
type Block struct {
|
||||
ContainerBounds elements.Bounds
|
||||
backgroundColor *color.Color
|
||||
mouse.NopHandler
|
||||
width float64
|
||||
height float64
|
||||
name string
|
||||
}
|
||||
|
||||
func (b *Block) Size() (w, h float64) {
|
||||
w, h = b.ContainerBounds.Width, b.ContainerBounds.Height
|
||||
if b.width != 0 {
|
||||
w = b.width
|
||||
}
|
||||
if b.height != 0 {
|
||||
h = b.height
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (b *Block) Draw(image *ebiten.Image) (w, h float64) {
|
||||
w, h = b.Size()
|
||||
if b.backgroundColor != nil {
|
||||
vector.DrawFilledRect(
|
||||
image,
|
||||
float32(b.ContainerBounds.Min.X),
|
||||
float32(b.ContainerBounds.Min.Y),
|
||||
float32(w),
|
||||
float32(h),
|
||||
*b.backgroundColor,
|
||||
true,
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user