From b7cd6d07fcaa69d009b3f33f7c59afb16b719029 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 31 Jan 2025 13:00:26 -0600 Subject: [PATCH] hmm. can't figure out where clicks are going --- color.go | 4 +- eventBindings.go | 11 +++++ eventMouse.go | 18 ++++---- eventMouseClick.go | 101 ++++++++++++++++++--------------------------- 4 files changed, 63 insertions(+), 71 deletions(-) diff --git a/color.go b/color.go index 6586d3a..dd26bb4 100644 --- a/color.go +++ b/color.go @@ -148,10 +148,10 @@ func (tk *guiWidget) setColor(newColor *colorT) { return } if tk.color == nil { - log.Log(NOW, "Set the node to color = nil") + // log.Log(NOW, "Set the node to color = nil") tk.color = &colorNone } - log.Log(NOW, "Set the node to color =", tk.color.name) + // log.Log(NOW, "Set the node to color =", tk.color.name) tk.Show() } diff --git a/eventBindings.go b/eventBindings.go index f8bcf41..c18ffdf 100644 --- a/eventBindings.go +++ b/eventBindings.go @@ -4,7 +4,10 @@ package main import ( + "fmt" + "github.com/awesome-gocui/gocui" + log "go.wit.com/log" ) // tells 'gocui' what to call based on what key was pressed @@ -44,6 +47,14 @@ func openDebuggger(g *gocui.Gui, v *gocui.View) error { return nil } +func theFind(g *gocui.Gui, v *gocui.View) error { + w, h := g.MousePosition() + for _, tk := range findByXY(w, h) { + log.Log(GOCUI, fmt.Sprintf("findByXY() 'f' key %-8s wId=%4d at (%3d,%3d) %s", tk.WidgetType, tk.node.WidgetId, w, h, tk.node.String())) + } + 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 diff --git a/eventMouse.go b/eventMouse.go index 3735010..9821bd1 100644 --- a/eventMouse.go +++ b/eventMouse.go @@ -65,11 +65,9 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error { w, h := g.MousePosition() // useful to debug everything that is being clicked on - /* - 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)) - } - */ + 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) @@ -96,9 +94,13 @@ 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() + var found bool = false + for _, tk := range findByXY(mx, my) { + log.Log(GOCUI, fmt.Sprintf("findByXY() mouseDown() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, mx, my)) + found = true + } + if !found { + log.Log(GOCUI, fmt.Sprintf("findByXY() mouseDown() found nothing at (%d,%d)", mx, my)) } vx0, vy0, vx1, vy1, err := g.ViewPosition("msg") diff --git a/eventMouseClick.go b/eventMouseClick.go index 01ad344..07235e4 100644 --- a/eventMouseClick.go +++ b/eventMouseClick.go @@ -8,29 +8,12 @@ import ( "go.wit.com/widget" ) -func (w *guiWidget) doWidgetClick() { - switch w.WidgetType { - /* - case widget.Root: - // THIS IS THE BEGINING OF THE LAYOUT - log.Log(GOCUI, "doWidgetClick()", w.String()) - wRoot := me.treeRoot.TK.(*guiWidget) - wRoot.redoWindows(0, 0) - case widget.Flag: - log.Log(GOCUI, "doWidgetClick() FLAG widget name =", w.String()) - log.Log(GOCUI, "doWidgetClick() if this is the dropdown menu, handle it here?") - */ +// this whole things was impossible to make but it got me where I am now +// the debugging is way way better now with it being visible in the Stdout window +// so now it's possible to redo all this and make it better +func (tk *guiWidget) doWidgetClick(w int, h int) { + switch tk.WidgetType { case widget.Window: - log.Log(GOCUI, "doWidgetClick() START on window", w.String()) - // if the user clicked on the current window, do nothing - /* Ignore this for now and redraw the window anyway - if me.currentWindow == w { - if !w.active { - return - } - } - */ - // if there is a current window, hide it if me.currentWindow != nil { me.currentWindow.setColor(&colorWindow) @@ -39,72 +22,67 @@ func (w *guiWidget) doWidgetClick() { } // now set this window as the current window - me.currentWindow = w + me.currentWindow = tk me.currentWindow.isCurrent = true // draw the current window - log.Log(GOCUI, "doWidgetClick() set currentWindow to", w.String()) - w.setColor(&colorActiveW) - w.DrawAt(3, 2) - w.placeWidgets(3, 2) // compute the sizes & places for each widget - w.active = false - w.showWidgets() - /* - hideFake() - showDebug = true - */ + tk.setColor(&colorActiveW) + tk.DrawAt(3, 2) + tk.placeWidgets(3, 2) // compute the sizes & places for each widget + tk.active = false + tk.showWidgets() case widget.Group: - if w.active { - w.active = false - w.placeWidgets(w.startW, w.startH) - w.showWidgets() + if tk.active { + tk.active = false + tk.placeWidgets(tk.startW, tk.startH) + tk.showWidgets() } else { - w.active = true - for _, child := range w.children { + tk.active = true + for _, child := range tk.children { child.hideWidgets() } } case widget.Checkbox: - if w.node.State.Checked { + if tk.node.State.Checked { log.Log(WARN, "checkbox is being set to false") - w.node.State.Checked = false - w.setCheckbox() + tk.node.State.Checked = false + tk.setCheckbox() } else { log.Log(WARN, "checkbox is being set to true") - w.node.State.Checked = true - w.setCheckbox() + tk.node.State.Checked = true + tk.setCheckbox() } - me.myTree.SendUserEvent(w.node) + me.myTree.SendUserEvent(tk.node) case widget.Grid: - newR := w.realGocuiSize() + newR := tk.realGocuiSize() // w,h := n.logicalSize() // w := newR.w1 - newR.w0 // h := newR.h1 - newR.h0 - w.placeGrid(newR.w0, newR.h0) - w.showWidgets() + tk.placeGrid(newR.w0, newR.h0) + tk.showWidgets() case widget.Box: - // w.showWidgetPlacement(logNow, "drawTree()") - if w.node.State.Direction == widget.Horizontal { - log.Log(GOCUI, "BOX IS HORIZONTAL", w.String()) + if tk.node.State.Direction == widget.Horizontal { + log.Log(GOCUI, "BOX IS HORIZONTAL", tk.String()) } else { - log.Log(GOCUI, "BOX IS VERTICAL", w.String()) + log.Log(GOCUI, "BOX IS VERTICAL", tk.String()) } - w.placeWidgets(w.startW, w.startH) - w.toggleTree() + tk.placeWidgets(tk.startW, tk.startH) + tk.toggleTree() case widget.Button: // doUserEvent(n) - me.myTree.SendFromUser(w.node) + me.myTree.SendFromUser(tk.node) case widget.Combobox: log.Log(GOCUI, "do the combobox here") - w.showDropdown() - me.dropdownW = w + tk.showDropdown() + me.dropdownW = tk case widget.Dropdown: log.Log(GOCUI, "do the dropdown here") - w.showDropdown() - me.dropdownW = w + tk.showDropdown() + me.dropdownW = tk default: + log.Log(GOCUI, fmt.Sprintf("findByXY() blank click() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h)) } } @@ -116,12 +94,13 @@ func click(g *gocui.Gui, v *gocui.View) error { h := mouseH 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)) + // will show you everything found on a mouse click. great for debugging! + // log.Log(GOCUI, fmt.Sprintf("findByXY() click() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h)) if tk.WidgetType == widget.Stdout { // don't send clicks to the stdout debugging window continue } - tk.doWidgetClick() + tk.doWidgetClick(w, h) return nil }