Files
games/common/elements/v1/element.go

43 lines
641 B
Go

package elements
import (
"github.com/hajimehoshi/ebiten/v2"
)
type InitFunc func() Element
type Element interface {
Draw(*ebiten.Image)
SetAnchor(Point)
Anchor() Point
Size() (w, h int)
Children() []Element
}
type Point struct {
X, Y int
}
func (p Point) Delta(p2 Point) Point {
return Point{
X: p2.X - p.X,
Y: p2.Y - p.Y,
}
}
func (p Point) Add(p2 Point) Point {
return Point{
X: p.X + p2.X,
Y: p.Y + p2.Y,
}
}
type Bounds struct {
Min Point
Width, Height int
}
func (b *Bounds) Contains(p Point) bool {
return p.X >= b.Min.X && p.X <= b.Min.X+b.Width && p.Y >= b.Min.Y && p.Y <= b.Min.Y+b.Height
}