trying to delay on mouse drag
This commit is contained in:
parent
83b4d7142a
commit
0aa82f5ba5
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
3
init.go
3
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"
|
||||
|
|
14
structs.go
14
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
|
||||
|
|
14
window.go
14
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")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue