From 73de9899a890d3babfebb2427397fb82dcc021c9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 31 Jan 2025 11:01:47 -0600 Subject: hmm. mouse click detection is better. now what? --- eventBindings.go | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ eventKeyboard.go | 90 ------------------------------------------------------ eventMouse.go | 19 +++++++++++- eventMouseClick.go | 61 +++++++++++------------------------- 4 files changed, 126 insertions(+), 134 deletions(-) create mode 100644 eventBindings.go delete mode 100644 eventKeyboard.go diff --git a/eventBindings.go b/eventBindings.go new file mode 100644 index 0000000..f8bcf41 --- /dev/null +++ b/eventBindings.go @@ -0,0 +1,90 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is (now) governed by the GPL 3.0 + +package main + +import ( + "github.com/awesome-gocui/gocui" +) + +// tells 'gocui' what to call based on what key was pressed +func registerHandlers(g *gocui.Gui) { + g.SetKeybinding("", '?', gocui.ModNone, theHelp) // 'h' toggles on and off the help menu + g.SetKeybinding("", 'r', gocui.ModNone, widgetRefresh) // screen refresh + g.SetKeybinding("", 'w', gocui.ModNone, doWindow) // close all windows + g.SetKeybinding("", 'q', gocui.ModNone, doExit) // exit + g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, doExit) // exit + g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone, doPanic) // forced panic + + // debugging + g.SetKeybinding("", 'd', gocui.ModNone, theLetterD) // 'd' toggles on and off debugging buttons + g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, openDebuggger) // open the debugger + g.SetKeybinding("", 'L', gocui.ModNone, dumpWidgets) // list all widgets + g.SetKeybinding("", 'M', gocui.ModNone, dumpWidgetPlacement) // list all widgets with positions + +} + +func doExit(g *gocui.Gui, v *gocui.View) error { + return nil +} + +func doPanic(g *gocui.Gui, v *gocui.View) error { + return nil +} + +func dumpWidgets(g *gocui.Gui, v *gocui.View) error { + return nil +} + +func dumpWidgetPlacement(g *gocui.Gui, v *gocui.View) error { + return nil +} + +func openDebuggger(g *gocui.Gui, v *gocui.View) error { + return nil +} + +// is run whenever anyone hits 'd' (in an open space) +func theLetterD(g *gocui.Gui, v *gocui.View) error { + // widgets that don't have physical existance in + // a display toolkit are hidden. In the case + // of gocui, they are set as not 'visible' and put offscreen + // or have the size set to zero + // (hopefully anyway) lots of things with the toolkit + // still don't work + + fakeStartWidth = me.FakeW + fakeStartHeight = me.TabH + me.FramePadH + if showDebug { + showFake() + showDebug = false + } else { + hideFake() + showDebug = true + } + return nil +} + +func theHelp(g *gocui.Gui, v *gocui.View) error { + if showHelp { + helplayout() + showHelp = false + if me.dropdownV == nil { + me.dropdownV = makeDropdownView("addWidget() ddview") + } + me.dropdownV.Show() + } else { + me.baseGui.DeleteView("help") + showHelp = true + me.dropdownV.Hide() + } + return nil +} + +func widgetRefresh(g *gocui.Gui, v *gocui.View) error { + return nil +} + +func doWindow(g *gocui.Gui, v *gocui.View) error { + return nil +} diff --git a/eventKeyboard.go b/eventKeyboard.go deleted file mode 100644 index f8bcf41..0000000 --- a/eventKeyboard.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2017-2025 WIT.COM Inc. All rights reserved. -// Use of this source code is (now) governed by the GPL 3.0 - -package main - -import ( - "github.com/awesome-gocui/gocui" -) - -// tells 'gocui' what to call based on what key was pressed -func registerHandlers(g *gocui.Gui) { - g.SetKeybinding("", '?', gocui.ModNone, theHelp) // 'h' toggles on and off the help menu - g.SetKeybinding("", 'r', gocui.ModNone, widgetRefresh) // screen refresh - g.SetKeybinding("", 'w', gocui.ModNone, doWindow) // close all windows - g.SetKeybinding("", 'q', gocui.ModNone, doExit) // exit - g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, doExit) // exit - g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone, doPanic) // forced panic - - // debugging - g.SetKeybinding("", 'd', gocui.ModNone, theLetterD) // 'd' toggles on and off debugging buttons - g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, openDebuggger) // open the debugger - g.SetKeybinding("", 'L', gocui.ModNone, dumpWidgets) // list all widgets - g.SetKeybinding("", 'M', gocui.ModNone, dumpWidgetPlacement) // list all widgets with positions - -} - -func doExit(g *gocui.Gui, v *gocui.View) error { - return nil -} - -func doPanic(g *gocui.Gui, v *gocui.View) error { - return nil -} - -func dumpWidgets(g *gocui.Gui, v *gocui.View) error { - return nil -} - -func dumpWidgetPlacement(g *gocui.Gui, v *gocui.View) error { - return nil -} - -func openDebuggger(g *gocui.Gui, v *gocui.View) error { - return nil -} - -// is run whenever anyone hits 'd' (in an open space) -func theLetterD(g *gocui.Gui, v *gocui.View) error { - // widgets that don't have physical existance in - // a display toolkit are hidden. In the case - // of gocui, they are set as not 'visible' and put offscreen - // or have the size set to zero - // (hopefully anyway) lots of things with the toolkit - // still don't work - - fakeStartWidth = me.FakeW - fakeStartHeight = me.TabH + me.FramePadH - if showDebug { - showFake() - showDebug = false - } else { - hideFake() - showDebug = true - } - return nil -} - -func theHelp(g *gocui.Gui, v *gocui.View) error { - if showHelp { - helplayout() - showHelp = false - if me.dropdownV == nil { - me.dropdownV = makeDropdownView("addWidget() ddview") - } - me.dropdownV.Show() - } else { - me.baseGui.DeleteView("help") - showHelp = true - me.dropdownV.Hide() - } - return nil -} - -func widgetRefresh(g *gocui.Gui, v *gocui.View) error { - return nil -} - -func doWindow(g *gocui.Gui, v *gocui.View) error { - return nil -} 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 } -- cgit v1.2.3