From 0aa82f5ba56f9e393e681971115881cc185f20c8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 8 Feb 2025 08:07:03 -0600 Subject: [PATCH] trying to delay on mouse drag --- eventMouse.go | 16 ++++++++++++++++ eventMouseClick.go | 4 +++- eventMouseMove.go | 13 +++++++++++-- init.go | 3 ++- structs.go | 14 ++++++++++++++ window.go | 14 ++++---------- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/eventMouse.go b/eventMouse.go index f2e1a92..7cf729e 100644 --- a/eventMouse.go +++ b/eventMouse.go @@ -4,6 +4,8 @@ package main import ( + "time" + "github.com/awesome-gocui/gocui" "go.wit.com/log" @@ -20,6 +22,7 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error { } */ + me.mouse.mouseUp = true me.globalMouseDown = false me.currentDrag = nil @@ -33,6 +36,19 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error { // the right response for the toolkit user's app func mouseDown(g *gocui.Gui, v *gocui.View) error { me.globalMouseDown = true + if me.mouse.mouseUp { + me.mouse.mouseUp = false + me.mouse.down = time.Now() + w, h := g.MousePosition() + me.mouse.downW = w + me.mouse.downH = h + return nil + } + + if time.Since(me.mouse.down) < me.mouse.clicktime { + log.Info("not yet") + return nil + } w, h := g.MousePosition() me.downW = w diff --git a/eventMouseClick.go b/eventMouseClick.go index d2562c0..675aeac 100644 --- a/eventMouseClick.go +++ b/eventMouseClick.go @@ -31,6 +31,8 @@ func (tk *guiWidget) DeleteNode() { func (tk *guiWidget) doWindowClick() { w, h := me.baseGui.MousePosition() + tk.dumpWidget(fmt.Sprintf("doWindowClick(%d,%d)", w, h)) + // compare the mouse location to the 'X' indicator to close the window if tk.gocuiSize.inRect(w, h) { offset := w - tk.gocuiSize.w1 @@ -57,7 +59,6 @@ func (tk *guiWidget) doWindowClick() { } } else { tk.window.collapsed = false - // tk.dumpWidget(fmt.Sprintf("No (%d,%d)", w, h)) } // if there is a current window, hide it if me.currentWindow != nil { @@ -75,6 +76,7 @@ func (tk *guiWidget) doWindowClick() { // 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) { + tk.dumpWidget(fmt.Sprintf("doWidgetClick(%d,%d)", w, h)) switch tk.node.WidgetType { case widget.Window: tk.doWindowClick() diff --git a/eventMouseMove.go b/eventMouseMove.go index eb6c2ee..2c70881 100644 --- a/eventMouseMove.go +++ b/eventMouseMove.go @@ -22,20 +22,29 @@ import ( // this function uses the mouse position to highlight & unhighlight things // this is run every time the user moves the mouse over the terminal window func mouseMove(g *gocui.Gui) { - w, h := g.MousePosition() me.ok = true // this tells init() it's okay to work with gocui - + // very useful for debugging in the past. also, just fun if me.supermouse { + w, h := g.MousePosition() for _, tk := range findByXY(w, h) { s := fmt.Sprintf("SM (%3d,%3d)", w, h) tk.dumpWidget(s) } } + /* + if time.Since(me.mouse.down) < me.mouse.clicktime { + log.Info("not yet") + return + } + */ + + w, h := g.MousePosition() // toggle off all highlight vies except for whatever is under the mouse for _, view := range g.Views() { view.Highlight = false } + if v, err := g.ViewByPosition(w, h); err == nil { v.Highlight = true } diff --git a/init.go b/init.go index 7545da0..05db9fc 100644 --- a/init.go +++ b/init.go @@ -50,7 +50,8 @@ func init() { me.textbox.wId = -55 me.stdout.wId = -4 - // Set(&me, "dense") + me.mouse.mouseUp = true + me.mouse.clicktime = time.Millisecond * 500 me.myTree = tree.New() me.myTree.PluginName = "gocui" diff --git a/structs.go b/structs.go index 3e10910..c7368de 100644 --- a/structs.go +++ b/structs.go @@ -13,6 +13,7 @@ import ( "reflect" "strconv" "sync" + "time" "github.com/awesome-gocui/gocui" @@ -73,6 +74,19 @@ type config struct { downH int // where the mouse was pressed down currentDrag *guiWidget // what widget is currently being moved around dark bool // use a 'dark' color palette + mouse mouse // mouse settings +} + +// stuff controlling how the mouse works +type mouse struct { + down time.Time // when the mouse was pressed down + up time.Time // when the mouse was released. used to detect click vs drag + clicktime time.Duration // how long is too long for a mouse click vs drag + mouseUp bool // is the mouse up? + downW int // where the mouse was pressed down + downH int // where the mouse was pressed down + currentDrag *guiWidget // what widget is currently being moved around + globalMouseDown bool // yep, mouse is pressed } // settings for the stdout window diff --git a/window.go b/window.go index 298d3ab..21d6cd8 100644 --- a/window.go +++ b/window.go @@ -24,7 +24,8 @@ func (tk *guiWidget) setTitle(s string) { me.baseGui.SetView(tk.v.Name(), rect.w0, rect.h0, rect.w1, rect.h1, 0) tk.v.Clear() f := "%-" + fmt.Sprintf("%d", tk.full.Width()-3) + "s %s" - tmp := tk.node.GetLabel() + " " + tk.v.Name() + " " + f + // tmp := tk.node.GetLabel() + " " + tk.v.Name() + " " + f + tmp := tk.node.GetLabel() labelN := fmt.Sprintf(f, tmp, "XX") tk.v.WriteString(labelN) } @@ -41,7 +42,7 @@ func (tk *guiWidget) redrawWindow(w int, h int) { tk.gocuiSize.w0 = w tk.gocuiSize.h0 = h tk.gocuiSize.w1 = w + len(tk.node.GetLabel()) - tk.labelN = tk.node.GetLabel() + " XX" + tk.labelN = tk.node.GetLabel() // could set XX here also but don't have final size of window yet tk.force.w0 = w tk.force.w1 = w tk.force.h0 = h @@ -112,14 +113,7 @@ func (tk *guiWidget) redrawWindow(w int, h int) { tk.hideWidgets() tk.showWidgets() - /* - tk.gocuiSize.w1 = tk.gocuiSize.w0 + tk.full.Width() - f := "%-" + fmt.Sprintf("%d", tk.full.Width()) + "s %s" - tk.labelN = fmt.Sprintf(f, tk.node.GetLabel(), "XX") - log.Info("f =", f) - log.Info("label =", tk.labelN) - tk.dumpWidget(fmt.Sprintf("label")) - */ + // draw the window title tk.setTitle(tk.node.GetLabel() + " jwc") }