diff options
Diffstat (limited to 'go/ui/widget.go')
| -rw-r--r-- | go/ui/widget.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/go/ui/widget.go b/go/ui/widget.go index 4ee0caac..da12929d 100644 --- a/go/ui/widget.go +++ b/go/ui/widget.go @@ -8,17 +8,31 @@ type Widget interface { Draw(*ebiten.Image) FindObjectAt(int, int) interface{} Contains(int, int) bool + Layout() (int, int) + + IsClickable() bool + Click(int, int) + // IsHoverable() bool + // Hover(int, int) + IsScrollable() bool + Scroll(int, int) + IsUpdatable() bool + Update() error + IsFocusable() bool + Focus(bool) } type WidgetBase struct { X, Y int Width, Height int img *ebiten.Image + Op *ebiten.DrawImageOptions renderImpl func() *ebiten.Image + EventHandlersMap } func NewWidgetBase(x, y, width, height int) WidgetBase { - return WidgetBase{X: x, Y: y, Width: width, Height: height} + return WidgetBase{X: x, Y: y, Width: width, Height: height, Op: &ebiten.DrawImageOptions{}, EventHandlersMap: NewEventHandlersMap()} } func (w *WidgetBase) Draw(screen *ebiten.Image) { @@ -26,10 +40,15 @@ func (w *WidgetBase) Draw(screen *ebiten.Image) { w.img = w.renderImpl() } op := &ebiten.DrawImageOptions{} + op.GeoM.Concat(w.Op.GeoM) op.GeoM.Translate(float64(w.X), float64(w.Y)) screen.DrawImage(w.img, op) } +func (w *WidgetBase) DrawImageOptions() *ebiten.DrawImageOptions { + return w.Op +} + func (w *WidgetBase) ForceRedraw() { w.img = nil } @@ -41,3 +60,7 @@ func (w *WidgetBase) Contains(x, y int) bool { func (w *WidgetBase) FindObjectAt(int, int) interface{} { return nil } + +func (w *WidgetBase) Layout() (int, int) { + return w.Width, w.Height +} |
