package ui import ( "github.com/hajimehoshi/ebiten/v2" ) type Widget interface { Draw(*ebiten.Image) FindObjectAt(int, int) interface{} Contains(int, int) bool } type WidgetBase struct { X, Y int Width, Height int img *ebiten.Image renderImpl func() *ebiten.Image } func NewWidgetBase(x, y, width, height int) WidgetBase { return WidgetBase{X: x, Y: y, Width: width, Height: height} } func (w *WidgetBase) Draw(screen *ebiten.Image) { if w.img == nil { w.img = w.renderImpl() } op := &ebiten.DrawImageOptions{} op.GeoM.Translate(float64(w.X), float64(w.Y)) screen.DrawImage(w.img, op) } func (w *WidgetBase) ForceRedraw() { w.img = nil } func (w *WidgetBase) Contains(x, y int) bool { return x >= 0 && y >= 0 && x >= w.X && x <= w.X+w.Width && y >= w.Y && y <= w.Y+w.Height } func (w *WidgetBase) FindObjectAt(int, int) interface{} { return nil }