diff --git a/eventKeyboard.go b/eventBindings.go similarity index 100% rename from eventKeyboard.go rename to eventBindings.go diff --git a/eventMouse.go b/eventMouse.go index 88702c3..a50142a 100644 --- a/eventMouse.go +++ b/eventMouse.go @@ -37,11 +37,19 @@ func mouseMove(g *gocui.Gui) { } } +// I think this lets me drag the debugging window func msgDown(g *gocui.Gui, v *gocui.View) error { initialMouseX, initialMouseY = g.MousePosition() + w := initialMouseX + h := initialMouseY + + for _, tk := range findByXY(w, h) { + log.Log(GOCUI, fmt.Sprintf("findByXY() msgDown() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h)) + } + // debugging output - log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY) + // log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY) // vx, vy, _, _, err := g.ViewPosition("msg") @@ -56,6 +64,10 @@ func msgDown(g *gocui.Gui, v *gocui.View) error { func mouseUp(g *gocui.Gui, v *gocui.View) error { w, h := g.MousePosition() + for _, tk := range findByXY(w, h) { + log.Log(GOCUI, fmt.Sprintf("findByXY() mouseUp() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h)) + } + dropdownUnclicked(w, h) if msgMouseDown { @@ -81,6 +93,11 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error { func mouseDown(g *gocui.Gui, v *gocui.View) error { mx, my := g.MousePosition() + for _, w := range findByXY(mx, my) { + log.Log(GOCUI, fmt.Sprintf("findByXY() mouseDown() %s wId=%d cuiName=%s at (%d,%d)", w.WidgetType, w.node.WidgetId, w.cuiName, mx, my)) + // w.doWidgetClick() + } + vx0, vy0, vx1, vy1, err := g.ViewPosition("msg") if err == nil { if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 { diff --git a/eventMouseClick.go b/eventMouseClick.go index 787f00f..80a7919 100644 --- a/eventMouseClick.go +++ b/eventMouseClick.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/awesome-gocui/gocui" "go.wit.com/log" @@ -109,54 +109,29 @@ func (w *guiWidget) doWidgetClick() { } } +// sends the mouse click to a widget underneath func click(g *gocui.Gui, v *gocui.View) error { mouseW, mouseH := me.baseGui.MousePosition() - log.Log(GOCUI, "click() START gocui name:", v.Name(), mouseW, mouseH) - w := findUnderMouse() + w := mouseW + h := mouseH - // if the dropdown view is visible, process it no matter what - if me.dropdownV.Visible() { - me.dropdownV.dropdownClicked(mouseW, mouseH) - } - if w == me.dropdownV { + for _, tk := range findByXY(w, h) { + log.Log(GOCUI, fmt.Sprintf("findByXY() click() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h)) + tk.doWidgetClick() return nil } - if w == nil { - log.Error(errors.New("click() could not find widget for view =" + v.Name())) - } else { - log.Log(GOCUI, "click() Found widget =", w.node.WidgetId, w.String(), ",", w.labelN) - w.doWidgetClick() - } - - rootTK := me.treeRoot.TK.(*guiWidget) - realTK := rootTK.findWidgetByView(v) - if realTK == nil { - log.Error(errors.New("toolkit click() out of reality with gocui. v.Name() not in binary tree " + v.Name())) - log.Log(GOCUI, "click() END FAILURE ON gocui v.Name =", v.Name()) - // return nil // otherwise gocui exits - } - - // double check the widget view really still exists - nameTK := rootTK.findWidgetByName(v.Name()) - if nameTK == nil { - log.Error(errors.New("toolkit click() out of reality with gocui. v.Name() not in binary tree " + v.Name())) - return nil - } - if nameTK.v == nil { - log.Log(GOCUI, "click() maybe this widget has had it's view distroyed?", nameTK.cuiName, nameTK.WidgetType) - log.Log(GOCUI, "yep. it's gone now") - return nil - } - - // SetCurrentView dies if it's sent an non-existent view - if _, err := g.SetCurrentView(v.Name()); err != nil { - log.Log(GOCUI, "click() END v.Name =", v.Name(), "err =", err) - // return err // return causes gocui.MainLoop() to exit. Do we ever want that to happen here? - return nil - } - - log.Log(GOCUI, "click() END gocui name:", v.Name()) + log.Log(GOCUI, "click() nothing was at:", v.Name(), mouseW, mouseH) + return nil + /* + // not sure what SetCurrentView() does right now. it was here before + // SetCurrentView dies if it's sent an non-existent view + if _, err := g.SetCurrentView(v.Name()); err != nil { + log.Log(GOCUI, "click() END v.Name =", v.Name(), "err =", err) + // return err // return causes gocui.MainLoop() to exit. Do we ever want that to happen here? + return nil + } + */ return nil }