aboutsummaryrefslogtreecommitdiff
path: root/go/ui/clickable.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/ui/clickable.go')
-rw-r--r--go/ui/clickable.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/go/ui/clickable.go b/go/ui/clickable.go
new file mode 100644
index 00000000..761b7534
--- /dev/null
+++ b/go/ui/clickable.go
@@ -0,0 +1,40 @@
+package ui
+
+import (
+ "github.com/hajimehoshi/ebiten/v2"
+)
+
+type Clickable interface {
+ Click(x, y int)
+}
+
+type ClickWrapper struct {
+ w Widget
+ onClick func(x, y int)
+}
+
+func NewClickWrapper(w Widget, onClick func(x, y int)) *ClickWrapper {
+ return &ClickWrapper{w, onClick}
+}
+
+func (w *ClickWrapper) Draw(screen *ebiten.Image) {
+ w.w.Draw(screen)
+}
+
+func (w *ClickWrapper) FindObjectAt(x, y int) interface{} {
+ return w.w.FindObjectAt(x, y)
+}
+
+func (w *ClickWrapper) Contains(x, y int) bool {
+ return w.w.Contains(x, y)
+}
+
+func (w *ClickWrapper) Click(x, y int) {
+ w.onClick(x, y)
+}
+
+func (w *ClickWrapper) Scroll(x, y int) {
+ if w, ok := w.w.(Scrollable); ok {
+ w.Scroll(x, y)
+ }
+}