detect double click
This commit is contained in:
parent
44264df09d
commit
078a23e0e0
|
@ -13,8 +13,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
||||||
w, h := g.MousePosition()
|
|
||||||
|
|
||||||
// useful to debug everything that is being clicked on
|
// useful to debug everything that is being clicked on
|
||||||
/*
|
/*
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
|
@ -22,16 +20,13 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if time.Since(me.mouse.down) < me.mouse.clicktime {
|
|
||||||
log.Info("was a mouse click, not a drag")
|
|
||||||
}
|
|
||||||
|
|
||||||
me.mouse.mouseUp = true
|
me.mouse.mouseUp = true
|
||||||
me.globalMouseDown = false
|
me.mouse.globalMouseDown = false
|
||||||
me.currentDrag = nil
|
me.mouse.currentDrag = nil
|
||||||
|
|
||||||
dropdownUnclicked(w, h)
|
|
||||||
|
|
||||||
|
if time.Since(me.mouse.down) < me.mouse.clicktime {
|
||||||
|
doMouseClick(me.mouse.downW, me.mouse.downH)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +35,10 @@ 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 {
|
||||||
if me.mouse.mouseUp {
|
if me.mouse.mouseUp {
|
||||||
me.globalMouseDown = true
|
if time.Since(me.mouse.down) < me.mouse.doubletime {
|
||||||
|
log.Info("double click")
|
||||||
|
}
|
||||||
|
me.mouse.globalMouseDown = true
|
||||||
me.mouse.mouseUp = false
|
me.mouse.mouseUp = false
|
||||||
me.mouse.down = time.Now()
|
me.mouse.down = time.Now()
|
||||||
w, h := g.MousePosition()
|
w, h := g.MousePosition()
|
||||||
|
@ -55,8 +53,6 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
w, h := g.MousePosition()
|
w, h := g.MousePosition()
|
||||||
me.downW = w
|
|
||||||
me.downH = h
|
|
||||||
|
|
||||||
// if the dropdown is active, never do anything else
|
// if the dropdown is active, never do anything else
|
||||||
if me.dropdown.active {
|
if me.dropdown.active {
|
||||||
|
@ -123,13 +119,13 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
if tk.node.WidgetType == widget.Stdout {
|
if tk.node.WidgetType == widget.Stdout {
|
||||||
// tk.dumpWidget("stdout fixme drag()" + tk.labelN)
|
// tk.dumpWidget("stdout fixme drag()" + tk.labelN)
|
||||||
me.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
tk.dragW = w - tk.gocuiSize.w0
|
tk.dragW = w - tk.gocuiSize.w0
|
||||||
tk.dragH = h - tk.gocuiSize.h0
|
tk.dragH = h - tk.gocuiSize.h0
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// tk.dumpWidget("mouse drag()" + tk.labelN)
|
// tk.dumpWidget("mouse drag()" + tk.labelN)
|
||||||
me.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
tk.dragW = w - tk.gocuiSize.w0
|
tk.dragW = w - tk.gocuiSize.w0
|
||||||
tk.dragH = h - tk.gocuiSize.h0
|
tk.dragH = h - tk.gocuiSize.h0
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -6,7 +6,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
@ -109,18 +108,15 @@ func (tk *guiWidget) doWidgetClick(w int, h int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sends the mouse click to a widget underneath
|
// handles a mouse click
|
||||||
func clickOLD(g *gocui.Gui, v *gocui.View) error {
|
func doMouseClick(w int, h int) {
|
||||||
mouseW, mouseH := me.baseGui.MousePosition()
|
dropdownUnclicked(w, h)
|
||||||
|
|
||||||
w := mouseW
|
|
||||||
h := mouseH
|
|
||||||
|
|
||||||
// Flag widgets (dropdown menus, etc) are the highest priority. ALWAYS SEND MOUSE CLICKS THERE FIRST
|
// Flag widgets (dropdown menus, etc) are the highest priority. ALWAYS SEND MOUSE CLICKS THERE FIRST
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Flag {
|
if tk.node.WidgetType == widget.Flag {
|
||||||
tk.doWidgetClick(w, h)
|
tk.doWidgetClick(w, h)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +124,7 @@ func clickOLD(g *gocui.Gui, v *gocui.View) error {
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Button {
|
if tk.node.WidgetType == widget.Button {
|
||||||
tk.doWidgetClick(w, h)
|
tk.doWidgetClick(w, h)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,18 +136,9 @@ func clickOLD(g *gocui.Gui, v *gocui.View) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tk.doWidgetClick(w, h)
|
tk.doWidgetClick(w, h)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Log(GOCUI, "click() nothing was at:", v.Name(), mouseW, mouseH)
|
log.Log(GOCUI, "click() nothing was at:", w, h)
|
||||||
return nil
|
return
|
||||||
/*
|
|
||||||
// not sure what SetCurrentView() does right now. it was here before
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,11 @@ func mouseMove(g *gocui.Gui) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if me.dropdown.active || me.textbox.active {
|
||||||
|
// can't drag or do anything when dropdown or textbox are visible
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
w, h := g.MousePosition()
|
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() {
|
||||||
|
@ -56,30 +61,30 @@ func mouseMove(g *gocui.Gui) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if me.globalMouseDown && (me.dropdown.active || me.textbox.active) {
|
if me.mouse.globalMouseDown && (me.dropdown.active || me.textbox.active) {
|
||||||
log.Info("can't drag while dropdown or textbox are active", w, h)
|
log.Info("can't drag while dropdown or textbox are active", w, h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if me.globalMouseDown {
|
if me.mouse.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
|
||||||
var found bool = false
|
var found bool = false
|
||||||
if me.currentDrag != nil {
|
if me.mouse.currentDrag != nil {
|
||||||
// me.currentDrag.dumpWidget(fmt.Sprintf("MM (%3d,%3d)", w, h))
|
// me.mouse.currentDrag.dumpWidget(fmt.Sprintf("MM (%3d,%3d)", w, h))
|
||||||
me.currentDrag.moveNew()
|
me.mouse.currentDrag.moveNew()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// new function that is smarter
|
// new function that is smarter
|
||||||
if tk := findWindowUnderMouse(); tk != nil {
|
if tk := findWindowUnderMouse(); tk != nil {
|
||||||
me.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// first look for windows
|
// first look for windows
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Window {
|
if tk.node.WidgetType == widget.Window {
|
||||||
me.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,20 +92,20 @@ func mouseMove(g *gocui.Gui) {
|
||||||
// now look for the STDOUT window
|
// now look for the STDOUT window
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Flag {
|
if tk.node.WidgetType == widget.Flag {
|
||||||
me.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
// tk.moveNew()
|
// tk.moveNew()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Stdout {
|
if tk.node.WidgetType == widget.Stdout {
|
||||||
me.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
// tk.moveNew()
|
// tk.moveNew()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if tk.node.WidgetType == widget.Label {
|
if tk.node.WidgetType == widget.Label {
|
||||||
me.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
// tk.moveNew()
|
// tk.moveNew()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -130,7 +135,7 @@ func (tk *guiWidget) moveNew() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if tk.node.WidgetType == widget.Stdout {
|
if tk.node.WidgetType == widget.Stdout {
|
||||||
if me.stdout.resize {
|
if me.mouse.resize {
|
||||||
newW := w - me.stdout.lastW
|
newW := w - me.stdout.lastW
|
||||||
newH := h - me.stdout.lastH
|
newH := h - me.stdout.lastH
|
||||||
me.stdout.w = newW
|
me.stdout.w = newW
|
||||||
|
|
1
init.go
1
init.go
|
@ -52,6 +52,7 @@ func init() {
|
||||||
|
|
||||||
me.mouse.mouseUp = true
|
me.mouse.mouseUp = true
|
||||||
me.mouse.clicktime = time.Millisecond * 100
|
me.mouse.clicktime = time.Millisecond * 100
|
||||||
|
me.mouse.doubletime = time.Millisecond * 300
|
||||||
|
|
||||||
me.myTree = tree.New()
|
me.myTree = tree.New()
|
||||||
me.myTree.PluginName = "gocui"
|
me.myTree.PluginName = "gocui"
|
||||||
|
|
|
@ -63,16 +63,12 @@ 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
|
|
||||||
newWindowTrigger chan *guiWidget // work around hack to redraw windows a bit after NewWindow()
|
newWindowTrigger chan *guiWidget // work around hack to redraw windows a bit after NewWindow()
|
||||||
stdout stdout // information for the STDOUT window
|
stdout stdout // information for the STDOUT window
|
||||||
showDebug bool // todo: move this into config struct
|
showDebug bool // todo: move this into config struct
|
||||||
dropdown dropdown // the dropdown menu
|
dropdown dropdown // the dropdown menu
|
||||||
textbox dropdown // the textbox popup window
|
textbox dropdown // the textbox popup window
|
||||||
allwin []*guiWidget // for tracking which window is next
|
allwin []*guiWidget // for tracking which window is next
|
||||||
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
|
|
||||||
dark bool // use a 'dark' color palette
|
dark bool // use a 'dark' color palette
|
||||||
mouse mouse // mouse settings
|
mouse mouse // mouse settings
|
||||||
}
|
}
|
||||||
|
@ -83,6 +79,9 @@ type mouse struct {
|
||||||
up time.Time // when the mouse was released. used to detect click vs drag
|
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
|
clicktime time.Duration // how long is too long for a mouse click vs drag
|
||||||
mouseUp bool // is the mouse up?
|
mouseUp bool // is the mouse up?
|
||||||
|
double bool // user is double clicking
|
||||||
|
doubletime time.Duration // how long is too long for double click
|
||||||
|
resize bool // mouse is resizing something
|
||||||
downW int // where the mouse was pressed down
|
downW int // where the mouse was pressed down
|
||||||
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
|
||||||
|
@ -102,7 +101,6 @@ type stdout struct {
|
||||||
// mouseOffsetW int // the current 'w' offset
|
// mouseOffsetW int // the current 'w' offset
|
||||||
// mouseOffsetH int // the current 'h' offset
|
// mouseOffsetH int // the current 'h' offset
|
||||||
init bool // moves the window offscreen on startup
|
init bool // moves the window offscreen on startup
|
||||||
resize bool // user is resizing the window
|
|
||||||
outputS []string // the buffer of all the output
|
outputS []string // the buffer of all the output
|
||||||
pager int // allows the user to page through the buffer
|
pager int // allows the user to page through the buffer
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue