continue improvements on window dragging

This commit is contained in:
Jeff Carr 2025-02-06 09:30:54 -06:00
parent c4095ef7aa
commit 9fa974f6c4
4 changed files with 64 additions and 81 deletions

View File

@ -4,8 +4,6 @@
package main
import (
"fmt"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
@ -24,7 +22,7 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
log.Info("mouseUp() setting me.globalMouseDown = false")
me.globalMouseDown = false
currentDrag = nil
me.currentDrag = nil
dropdownUnclicked(w, h)
@ -38,8 +36,12 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
log.Info("mouseDown() setting globalMouseDown = true")
me.globalMouseDown = true
w, h := g.MousePosition()
me.downW = w
me.downH = h
// if the dropdown is active, never do anything else
if me.dropdown.active {
w, h := g.MousePosition()
log.Info("mouseDown() stopping here. dropdwon menu is in effect")
for _, tk := range findByXY(w, h) {
if (tk.node.WidgetType == widget.Flag) && (tk == me.dropdown.tk) {
@ -54,79 +56,48 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
return nil
}
var found bool = false
w, h := g.MousePosition()
for _, tk := range findByXY(w, h) {
tk.dumpWidget("mouseDown()")
if tk.node.WidgetType == widget.Button {
log.Info("SENDING CLICK TO Button")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Checkbox {
log.Info("SENDING CLICK TO Checkbox")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Dropdown {
log.Info("SENDING CLICK TO Dropdown")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Textbox {
log.Info("SENDING CLICK TO Textbox")
tk.doWidgetClick(w, h)
return nil
}
found = true
// figre out what window this is
tk := findWindowUnderMouse()
if tk == nil {
log.Info("mouseDown() nothing to click on at", w, h)
return nil
}
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) {
if tk.node.WidgetType == widget.Window {
tk.dragW = mx - tk.gocuiSize.w0
tk.dragH = my - tk.gocuiSize.h0
if (mx-tk.gocuiSize.w0 < 3) && (my-tk.gocuiSize.h0 < 3) {
log.Info("RESIZE WINDOW", tk.dragW, tk.dragH)
}
log.Info("SENDING CLICK TO WINDOW", tk.dragW, tk.dragH)
tk.doWidgetClick(mx-tk.dragW, my-tk.dragH)
return nil
}
if tk.node.WidgetType == widget.Label {
log.Info("IGNORE LABLE")
found = false
log.Info("setting mousedown to true for label")
// msgMouseDown = true
return nil
}
/*
if tk.node.WidgetType == widget.Label {
log.Info("SENDING CLICK TO Label")
tk.doWidgetClick(mx, my)
log.Info("SENDING mouseDown() to findWindowUnderMouse()")
if tk.node.WidgetType == widget.Window {
// check to see if this is a direct click on a widget
for _, tk := range tk.findByXYreal(w, h) {
tk.dumpWidget("mouseDown()")
if tk.node.WidgetType == widget.Button {
log.Info("SENDING CLICK TO Button")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Checkbox {
log.Info("SENDING CLICK TO Checkbox")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Dropdown {
log.Info("SENDING CLICK TO Dropdown")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Textbox {
log.Info("SENDING CLICK TO Textbox")
tk.doWidgetClick(w, h)
return nil
}
*/
found = true
}
if !found {
log.Log(GOCUI, fmt.Sprintf("mouseDown() found nothing at (%d,%d)", mx, my))
}
// sort this junk out
vx0, vy0, vx1, vy1, err := g.ViewPosition("msg")
if err == nil {
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {
return msgDown(g, v)
}
}
me.currentDrag = tk
tk.dragW = w - tk.gocuiSize.w0
tk.dragH = h - tk.gocuiSize.h0
tk.doWidgetClick(w-tk.dragW, w-tk.dragH)
return nil
// move the msg I guess
// return msgDown(g, v)
// return nil
}
// this needs to go

View File

@ -19,8 +19,6 @@ import (
"go.wit.com/widget"
)
var currentDrag *guiWidget
// 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) {
@ -43,19 +41,19 @@ func mouseMove(g *gocui.Gui) {
// plugin will segfault if you don't keep this inside a check for msgMouseDown
// don't move this code out of here
var found bool = false
if currentDrag != nil {
currentDrag.moveNew()
if me.currentDrag != nil {
me.currentDrag.moveNew()
return
}
// new function that is smarter
if tk := findWindowUnderMouse(); tk != nil {
currentDrag = tk
me.currentDrag = tk
return
}
// first look for windows
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Window {
currentDrag = tk
me.currentDrag = tk
return
}
}
@ -63,20 +61,20 @@ func mouseMove(g *gocui.Gui) {
// now look for the STDOUT window
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Flag {
currentDrag = tk
me.currentDrag = tk
// tk.moveNew()
return
}
}
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Stdout {
currentDrag = tk
me.currentDrag = tk
// tk.moveNew()
return
}
/*
if tk.node.WidgetType == widget.Label {
currentDrag = tk
me.currentDrag = tk
// tk.moveNew()
return
}

12
find.go
View File

@ -4,6 +4,8 @@
package main
import (
"fmt"
"github.com/awesome-gocui/gocui"
log "go.wit.com/log"
"go.wit.com/widget"
@ -133,9 +135,14 @@ func findNextWindow() *guiWidget {
func findWindowUnderMouse() *guiWidget {
w, h := me.baseGui.MousePosition()
if len(me.allwin) != len(findWindows()) {
me.allwin = findWindows()
}
// if the stdout window is on top, check it first
if me.stdout.outputOnTop {
if me.stdout.tk.full.inRect(w, h) {
log.Info(fmt.Sprintf("findWindowUnderMouse() found %s stdout on top (%dx%d)", me.stdout.tk.cuiName, w, h))
return me.stdout.tk
}
}
@ -144,6 +151,7 @@ func findWindowUnderMouse() *guiWidget {
for _, win := range me.allwin {
if win.activeWindow {
if win.full.inRect(w, h) {
log.Info(fmt.Sprintf("findWindowUnderMouse() found %s active window (%dx%d)", win.cuiName, w, h))
return win
}
}
@ -152,17 +160,19 @@ func findWindowUnderMouse() *guiWidget {
// well, just find any window then
for _, win := range me.allwin {
if win.full.inRect(w, h) {
log.Info(fmt.Sprintf("findWindowUnderMouse() found %s window (%dx%d)", win.cuiName, w, h))
return win
}
}
// okay, no window. maybe the stdout is there?
if me.stdout.tk.full.inRect(w, h) {
log.Info(fmt.Sprintf("findWindowUnderMouse() found %s stdout (%dx%d)", me.stdout.tk.cuiName, w, h))
return me.stdout.tk
}
// geez. nothing! maybe auto return stdout?
log.Info("no window found at", w, h)
log.Info("findWindowUnderMouse() no window found at", w, h)
return nil
}

View File

@ -69,6 +69,10 @@ type config struct {
showDebug bool // todo: move this into config struct
dropdown dropdown // the dropdown menu
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
}
// settings for the stdout window