trying to delay on mouse drag

This commit is contained in:
Jeff Carr 2025-02-08 08:07:03 -06:00
parent 83b4d7142a
commit 0aa82f5ba5
6 changed files with 50 additions and 14 deletions

View File

@ -4,6 +4,8 @@
package main package main
import ( import (
"time"
"github.com/awesome-gocui/gocui" "github.com/awesome-gocui/gocui"
"go.wit.com/log" "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.globalMouseDown = false
me.currentDrag = nil 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 // 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 {
me.globalMouseDown = true 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() w, h := g.MousePosition()
me.downW = w me.downW = w

View File

@ -31,6 +31,8 @@ func (tk *guiWidget) DeleteNode() {
func (tk *guiWidget) doWindowClick() { func (tk *guiWidget) doWindowClick() {
w, h := me.baseGui.MousePosition() 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 // compare the mouse location to the 'X' indicator to close the window
if tk.gocuiSize.inRect(w, h) { if tk.gocuiSize.inRect(w, h) {
offset := w - tk.gocuiSize.w1 offset := w - tk.gocuiSize.w1
@ -57,7 +59,6 @@ func (tk *guiWidget) doWindowClick() {
} }
} else { } else {
tk.window.collapsed = false tk.window.collapsed = false
// tk.dumpWidget(fmt.Sprintf("No (%d,%d)", w, h))
} }
// if there is a current window, hide it // if there is a current window, hide it
if me.currentWindow != nil { 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 // 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 // so now it's possible to redo all this and make it better
func (tk *guiWidget) doWidgetClick(w int, h int) { func (tk *guiWidget) doWidgetClick(w int, h int) {
tk.dumpWidget(fmt.Sprintf("doWidgetClick(%d,%d)", w, h))
switch tk.node.WidgetType { switch tk.node.WidgetType {
case widget.Window: case widget.Window:
tk.doWindowClick() tk.doWindowClick()

View File

@ -22,20 +22,29 @@ import (
// this function uses the mouse position to highlight & unhighlight things // this function uses the mouse position to highlight & unhighlight things
// this is run every time the user moves the mouse over the terminal window // this is run every time the user moves the mouse over the terminal window
func mouseMove(g *gocui.Gui) { func mouseMove(g *gocui.Gui) {
w, h := g.MousePosition()
me.ok = true // this tells init() it's okay to work with gocui 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 { if me.supermouse {
w, h := g.MousePosition()
for _, tk := range findByXY(w, h) { for _, tk := range findByXY(w, h) {
s := fmt.Sprintf("SM (%3d,%3d)", w, h) s := fmt.Sprintf("SM (%3d,%3d)", w, h)
tk.dumpWidget(s) 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 // toggle off all highlight vies except for whatever is under the mouse
for _, view := range g.Views() { for _, view := range g.Views() {
view.Highlight = false view.Highlight = false
} }
if v, err := g.ViewByPosition(w, h); err == nil { if v, err := g.ViewByPosition(w, h); err == nil {
v.Highlight = true v.Highlight = true
} }

View File

@ -50,7 +50,8 @@ func init() {
me.textbox.wId = -55 me.textbox.wId = -55
me.stdout.wId = -4 me.stdout.wId = -4
// Set(&me, "dense") me.mouse.mouseUp = true
me.mouse.clicktime = time.Millisecond * 500
me.myTree = tree.New() me.myTree = tree.New()
me.myTree.PluginName = "gocui" me.myTree.PluginName = "gocui"

View File

@ -13,6 +13,7 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"sync" "sync"
"time"
"github.com/awesome-gocui/gocui" "github.com/awesome-gocui/gocui"
@ -73,6 +74,19 @@ type config struct {
downH int // where the mouse was pressed down downH int // where the mouse was pressed down
currentDrag *guiWidget // what widget is currently being moved around currentDrag *guiWidget // what widget is currently being moved around
dark bool // use a 'dark' color palette 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 // settings for the stdout window

View File

@ -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) me.baseGui.SetView(tk.v.Name(), rect.w0, rect.h0, rect.w1, rect.h1, 0)
tk.v.Clear() tk.v.Clear()
f := "%-" + fmt.Sprintf("%d", tk.full.Width()-3) + "s %s" 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") labelN := fmt.Sprintf(f, tmp, "XX")
tk.v.WriteString(labelN) tk.v.WriteString(labelN)
} }
@ -41,7 +42,7 @@ func (tk *guiWidget) redrawWindow(w int, h int) {
tk.gocuiSize.w0 = w tk.gocuiSize.w0 = w
tk.gocuiSize.h0 = h tk.gocuiSize.h0 = h
tk.gocuiSize.w1 = w + len(tk.node.GetLabel()) 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.w0 = w
tk.force.w1 = w tk.force.w1 = w
tk.force.h0 = h tk.force.h0 = h
@ -112,14 +113,7 @@ func (tk *guiWidget) redrawWindow(w int, h int) {
tk.hideWidgets() tk.hideWidgets()
tk.showWidgets() tk.showWidgets()
/* // draw the window title
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"))
*/
tk.setTitle(tk.node.GetLabel() + " jwc") tk.setTitle(tk.node.GetLabel() + " jwc")
} }