not sure why mouse clicks are working weird
This commit is contained in:
parent
c136ca2b4c
commit
c4095ef7aa
|
@ -92,27 +92,6 @@ func addDropdown() *tree.Node {
|
|||
return addDropdownNew(-222)
|
||||
}
|
||||
|
||||
func findNextWindow() *guiWidget {
|
||||
var found bool
|
||||
if len(me.allwin) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, win := range me.allwin {
|
||||
if win.activeWindow {
|
||||
found = true
|
||||
win.activeWindow = false
|
||||
continue
|
||||
}
|
||||
if found {
|
||||
win.activeWindow = true
|
||||
return win
|
||||
}
|
||||
}
|
||||
me.allwin[0].activeWindow = true
|
||||
// at the end, loop to the beginning
|
||||
return me.allwin[0]
|
||||
}
|
||||
|
||||
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
||||
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
||||
log.Info("got keypress 2. now what?")
|
||||
|
|
|
@ -80,6 +80,12 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
|||
}
|
||||
found = true
|
||||
}
|
||||
if tk := findWindowUnderMouse(); tk != nil {
|
||||
w, h := g.MousePosition()
|
||||
tk.dragW = w - tk.gocuiSize.w0
|
||||
tk.dragH = h - tk.gocuiSize.h0
|
||||
tk.doWidgetClick(w-tk.dragW, w-tk.dragH)
|
||||
}
|
||||
|
||||
mx, my := g.MousePosition()
|
||||
for _, tk := range findByXY(mx, my) {
|
||||
|
|
|
@ -47,6 +47,11 @@ func mouseMove(g *gocui.Gui) {
|
|||
currentDrag.moveNew()
|
||||
return
|
||||
}
|
||||
// new function that is smarter
|
||||
if tk := findWindowUnderMouse(); tk != nil {
|
||||
currentDrag = tk
|
||||
return
|
||||
}
|
||||
// first look for windows
|
||||
for _, tk := range findByXY(w, h) {
|
||||
if tk.node.WidgetType == widget.Window {
|
||||
|
|
46
find.go
46
find.go
|
@ -5,6 +5,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/awesome-gocui/gocui"
|
||||
log "go.wit.com/log"
|
||||
"go.wit.com/widget"
|
||||
)
|
||||
|
||||
|
@ -108,6 +109,27 @@ func (tk *guiWidget) findBG() *guiWidget {
|
|||
return nil
|
||||
}
|
||||
|
||||
func findNextWindow() *guiWidget {
|
||||
var found bool
|
||||
if len(me.allwin) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, win := range me.allwin {
|
||||
if win.activeWindow {
|
||||
found = true
|
||||
win.activeWindow = false
|
||||
continue
|
||||
}
|
||||
if found {
|
||||
win.activeWindow = true
|
||||
return win
|
||||
}
|
||||
}
|
||||
me.allwin[0].activeWindow = true
|
||||
// at the end, loop to the beginning
|
||||
return me.allwin[0]
|
||||
}
|
||||
|
||||
func findWindowUnderMouse() *guiWidget {
|
||||
w, h := me.baseGui.MousePosition()
|
||||
|
||||
|
@ -117,6 +139,30 @@ func findWindowUnderMouse() *guiWidget {
|
|||
return me.stdout.tk
|
||||
}
|
||||
}
|
||||
|
||||
// now check if the active window is below the mouse
|
||||
for _, win := range me.allwin {
|
||||
if win.activeWindow {
|
||||
if win.full.inRect(w, h) {
|
||||
return win
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// well, just find any window then
|
||||
for _, win := range me.allwin {
|
||||
if win.full.inRect(w, h) {
|
||||
return win
|
||||
}
|
||||
}
|
||||
|
||||
// okay, no window. maybe the stdout is there?
|
||||
if me.stdout.tk.full.inRect(w, h) {
|
||||
return me.stdout.tk
|
||||
}
|
||||
|
||||
// geez. nothing! maybe auto return stdout?
|
||||
log.Info("no window found at", w, h)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue