closer to mouse drag not being annoyingly wrong

This commit is contained in:
Jeff Carr 2025-02-01 21:28:52 -06:00
parent d5d0262013
commit ac9c6617e3
5 changed files with 58 additions and 44 deletions

View File

@ -23,8 +23,12 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
} }
*/ */
log.Info("mouseUp() setting me.globalMouseDown = false")
me.globalMouseDown = false
dropdownUnclicked(w, h) dropdownUnclicked(w, h)
/*
if msgMouseDown { if msgMouseDown {
log.Info("setting mousedown to false") log.Info("setting mousedown to false")
msgMouseDown = false msgMouseDown = false
@ -32,6 +36,7 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
globalMouseDown = false globalMouseDown = false
g.DeleteView("globalDown") g.DeleteView("globalDown")
} }
*/
return nil return nil
} }
@ -40,6 +45,7 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
// the right response for the toolkit user's app // the right response for the toolkit user's app
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()
me.globalMouseDown = true
var found bool = false var found bool = false
for _, tk := range findByXY(mx, my) { for _, tk := range findByXY(mx, my) {
@ -85,7 +91,6 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
return msgDown(g, v) return msgDown(g, v)
} }
} }
globalMouseDown = true
maxX, _ := g.Size() maxX, _ := g.Size()

View File

@ -33,7 +33,7 @@ func mouseMove(g *gocui.Gui) {
} }
} }
if msgMouseDown { if me.globalMouseDown {
// log.Info("msgMouseDown == true") // log.Info("msgMouseDown == true")
// plugin will segfault if you don't keep this inside a check for msgMouseDown // plugin will segfault if you don't keep this inside a check for msgMouseDown
// don't move this code out of here // don't move this code out of here
@ -75,13 +75,16 @@ func (tk *guiWidget) moveNew(g *gocui.Gui) {
if tk.node.WidgetType == widget.Label { if tk.node.WidgetType == widget.Label {
s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName) s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName)
tk.dumpWidget(s) tk.dumpWidget(s)
outputW, outputH := tk.Size()
g.SetView(tk.cuiName, w-xOffset, h-yOffset, w-xOffset+outputW, h-yOffset+outputH+me.FramePadH, 0) g.SetView(tk.cuiName, w-xOffset, h-yOffset, w-xOffset+outputW, h-yOffset+outputH+me.FramePadH, 0)
me.startOutputW = w - xOffset me.startOutputW = w - xOffset
me.startOutputH = h - yOffset me.startOutputH = h - yOffset
g.SetViewOnBottom(tk.cuiName) // g.SetViewOnBottom(tk.cuiName)
return return
} }
tk.dumpWidget("moveNew() on " + tk.cuiName) tk.dumpWidget("moveNew() on " + tk.cuiName)
outputW := 140
outputH := 40
g.SetView("msg", w-xOffset, h-yOffset, w-xOffset+outputW, h-yOffset+outputH+me.FramePadH, 0) g.SetView("msg", w-xOffset, h-yOffset, w-xOffset+outputW, h-yOffset+outputH+me.FramePadH, 0)
me.startOutputW = w - xOffset me.startOutputW = w - xOffset
me.startOutputH = h - yOffset me.startOutputH = h - yOffset

View File

@ -192,6 +192,8 @@ func (w *guiWidget) placeGrid(startW int, startH int) (int, int) {
func (w *guiWidget) realGocuiSize() *rectType { func (w *guiWidget) realGocuiSize() *rectType {
var f func(tk *guiWidget, r *rectType) var f func(tk *guiWidget, r *rectType)
newR := new(rectType) newR := new(rectType)
outputW, outputH := w.Size()
// initialize the values to opposite // initialize the values to opposite
newR.w0 = outputW newR.w0 = outputW
newR.h0 = outputH newR.h0 = outputH

View File

@ -13,9 +13,6 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
var outputW int = 180
var outputH int = 40
func showMsg(g *gocui.Gui, v *gocui.View) error { func showMsg(g *gocui.Gui, v *gocui.View) error {
var l string var l string
var err error var err error
@ -39,6 +36,9 @@ func showMsg(g *gocui.Gui, v *gocui.View) error {
func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
maxX, maxY := g.Size() maxX, maxY := g.Size()
var outputW int = 180
var outputH int = 40
if me.treeRoot == nil { if me.treeRoot == nil {
// keep skipping this until the binary tree is initialized // keep skipping this until the binary tree is initialized
return nil return nil

View File

@ -70,12 +70,13 @@ type config struct {
ecount int // counts how many mouse and keyboard events have occurred ecount int // counts how many mouse and keyboard events have occurred
supermouse bool // prints out every widget found while you move the mouse around supermouse bool // prints out every widget found while you move the mouse around
depth int // used for listWidgets() debugging depth int // used for listWidgets() debugging
globalMouseDown bool // yep, mouse is pressed
} }
// deprecate these // deprecate these
var ( var (
initialMouseX, initialMouseY, xOffset, yOffset int initialMouseX, initialMouseY, xOffset, yOffset int
globalMouseDown, msgMouseDown bool msgMouseDown bool
) )
// this is the gocui way // this is the gocui way
@ -131,6 +132,9 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
me.writeMutex.Lock() me.writeMutex.Lock()
defer me.writeMutex.Unlock() defer me.writeMutex.Unlock()
// _, outputH := w.Size()
outputH := 33 // special output length for "msg" window until I figure things out
tk := me.logStdout tk := me.logStdout
if tk.v == nil { if tk.v == nil {
// optionally write the output to /tmp // optionally write the output to /tmp