aboutsummaryrefslogtreecommitdiff
path: root/go/ui/collection.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/ui/collection.go')
-rw-r--r--go/ui/collection.go72
1 files changed, 14 insertions, 58 deletions
diff --git a/go/ui/collection.go b/go/ui/collection.go
index 9ccaa176..dfd5fbb5 100644
--- a/go/ui/collection.go
+++ b/go/ui/collection.go
@@ -133,49 +133,8 @@ func (c *Collection) switchFocus(fcsbl Widget) {
}
}
-func (c *Collection) handleTouchInputs() error {
- for i := len(TouchManager.Taps) - 1; i >= 0; i-- {
- tap := TouchManager.Taps[i]
- for i := len(c.widgets) - 1; i >= 0; i-- {
- w := c.widgets[i]
- if !w.Contains(tap.X, tap.Y) {
- continue
- }
- // Skip collections their widgets will receive left over input
- // during the following updateWidgets call,
- if _, ok := w.(CollectionInterface); ok {
- continue
- }
- if w.IsClickable() {
- w.Click(tap.X, tap.Y)
- }
- if w.IsFocusable() {
- c.switchFocus(w)
- } else if c.focused != nil {
- c.switchFocus(nil)
- }
- log.Printf("consume Tap for %T %v\n", w, w)
- TouchManager.consumeTap(i)
- break
- }
- }
-
- // TODO: handle pinching
- if TouchManager.Pan != nil {
- pan := TouchManager.Pan
- iX, iY := pan.Incremental()
-
- w := c.FindWidgetAt(int(pan.originX), (pan.originY))
- if w != nil && w.IsScrollable() {
- w.Scroll(int(iX)/10, int(iY)/10)
- }
- }
-
- return nil
-}
-
func passInput(ev InputEvent, textInput *TextInput) {
- textInput.AddInput(ev.ctx.(TextCtx).in)
+ textInput.AddInput(ev.Ctx.(TextCtx).in)
textInput.HandleKey()
}
@@ -198,38 +157,35 @@ func (c *Collection) updateWidgets() error {
func (c *Collection) Update() error {
defer c.updateWidgets()
- if err := c.handleTouchInputs(); err != nil {
- return err
- }
-
for i := len(Input) - 1; i >= 0; i-- {
ev := Input[i]
- w := c.FindWidgetAt(ev.x, ev.y)
+ w := c.FindWidgetAt(ev.X, ev.Y)
if w != nil {
- switch ev.kind {
- case Click:
- if w.IsClickable() && ev.ctx.(ClickCtx).btn == ebiten.MouseButtonLeft {
- w.Click(ev.x, ev.y)
- consumeInput(i)
+ switch ev.Kind {
+ case Click, Tap:
+ // Only consider taps or left clicks
+ if w.IsClickable() && (ev.Kind != Click || ev.Ctx.(ClickCtx).Btn == ebiten.MouseButtonLeft) {
+ w.Click(ev.X, ev.Y)
+ ConsumeInput(i)
}
// TODO: switch focus
- case Scroll:
+ case Scroll, Pan:
if w.IsScrollable() {
- s := ev.ctx.(ScrollCtx)
+ s := ev.Ctx.(DistanceCtx)
w.Scroll(s.scrollX, s.scrollY)
- consumeInput(i)
+ ConsumeInput(i)
}
case Text:
if txt, ok := w.(*TextInput); ok {
passInput(ev, txt)
- consumeInput(i)
+ ConsumeInput(i)
}
}
// handle focused text input
- } else if ev.kind == Text {
+ } else if ev.Kind == Text {
if txt, ok := c.focused.(*TextInput); ok {
passInput(ev, txt)
- consumeInput(i)
+ ConsumeInput(i)
}
}
}