hmm. mouse click detection is better. now what?

This commit is contained in:
Jeff Carr 2025-01-31 11:01:47 -06:00
parent c348940ca1
commit 73de9899a8
3 changed files with 36 additions and 44 deletions

View File

@ -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 { func msgDown(g *gocui.Gui, v *gocui.View) error {
initialMouseX, initialMouseY = g.MousePosition() 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 // debugging output
log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY) // log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY)
// //
vx, vy, _, _, err := g.ViewPosition("msg") 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 { func mouseUp(g *gocui.Gui, v *gocui.View) error {
w, h := g.MousePosition() 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) dropdownUnclicked(w, h)
if msgMouseDown { if msgMouseDown {
@ -81,6 +93,11 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
func mouseDown(g *gocui.Gui, v *gocui.View) error { func mouseDown(g *gocui.Gui, v *gocui.View) error {
mx, my := g.MousePosition() 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") vx0, vy0, vx1, vy1, err := g.ViewPosition("msg")
if err == nil { if err == nil {
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 { if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"errors" "fmt"
"github.com/awesome-gocui/gocui" "github.com/awesome-gocui/gocui"
"go.wit.com/log" "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 { func click(g *gocui.Gui, v *gocui.View) error {
mouseW, mouseH := me.baseGui.MousePosition() mouseW, mouseH := me.baseGui.MousePosition()
log.Log(GOCUI, "click() START gocui name:", v.Name(), mouseW, mouseH) w := mouseW
w := findUnderMouse() h := mouseH
// if the dropdown view is visible, process it no matter what for _, tk := range findByXY(w, h) {
if me.dropdownV.Visible() { log.Log(GOCUI, fmt.Sprintf("findByXY() click() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h))
me.dropdownV.dropdownClicked(mouseW, mouseH) tk.doWidgetClick()
}
if w == me.dropdownV {
return nil return nil
} }
if w == nil { log.Log(GOCUI, "click() nothing was at:", v.Name(), mouseW, mouseH)
log.Error(errors.New("click() could not find widget for view =" + v.Name())) return nil
} else { /*
log.Log(GOCUI, "click() Found widget =", w.node.WidgetId, w.String(), ",", w.labelN) // not sure what SetCurrentView() does right now. it was here before
w.doWidgetClick() // 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)
rootTK := me.treeRoot.TK.(*guiWidget) // return err // return causes gocui.MainLoop() to exit. Do we ever want that to happen here?
realTK := rootTK.findWidgetByView(v) return nil
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())
return nil return nil
} }