mouse dragging works correctly again

This commit is contained in:
Jeff Carr 2025-02-08 09:12:35 -06:00
parent b730ee9459
commit 1923f8df96
4 changed files with 25 additions and 63 deletions

View File

@ -117,9 +117,6 @@ func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
return nil
}
tk.makeWindowActive()
// w, h := g.MousePosition()
// me.downW = tk.gocuiSize.w0
// me.downH = tk.gocuiSize.h0
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
return nil

View File

@ -124,48 +124,6 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
}
}
}
if tk.node.WidgetType == widget.Stdout {
// tk.dumpWidget("stdout fixme drag()" + tk.labelN)
me.mouse.currentDrag = tk
tk.dragW = w - tk.gocuiSize.w0
tk.dragH = h - tk.gocuiSize.h0
return nil
}
// tk.dumpWidget("mouse drag()" + tk.labelN)
me.mouse.currentDrag = tk
tk.dragW = w - tk.gocuiSize.w0
tk.dragH = h - tk.gocuiSize.h0
return nil
}
/*
// this needs to go
// event triggers when you push down on a mouse button
func msgDown(g *gocui.Gui, v *gocui.View) error {
w, h := g.MousePosition()
for _, tk := range findByXY(w, h) {
tk.dumpWidget("msgDown()")
}
vx, vy, _, _, err := g.ViewPosition("msg")
if err == nil {
me.stdout.mouseOffsetW = w - vx
me.stdout.mouseOffsetH = h - vy
}
// did the user click in the corner of the stdout window? If so, resize the window.
cornerW := w - vx
cornerH := h - vy
if (me.stdout.w-cornerW < 4) && (me.stdout.h-cornerH < 4) {
log.Info("Resize msg", cornerW, cornerH)
me.stdout.resize = true
} else {
log.Info("not Resize msg", cornerW, cornerH)
me.stdout.resize = false
}
log.Info("setting mousedown to true for msg")
// msgMouseDown = true
return nil
}
*/

View File

@ -85,13 +85,13 @@ func mouseMove(g *gocui.Gui) {
}
// new function that is smarter
if tk := findWindowUnderMouse(); tk != nil {
me.mouse.currentDrag = tk
tk.setAsDragging()
return
}
// first look for windows
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Window {
me.mouse.currentDrag = tk
tk.setAsDragging()
return
}
}
@ -99,14 +99,13 @@ func mouseMove(g *gocui.Gui) {
// now look for the STDOUT window
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Flag {
me.mouse.currentDrag = tk
// tk.moveNew()
tk.setAsDragging()
return
}
}
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Stdout {
me.mouse.currentDrag = tk
tk.setAsDragging()
// tk.moveNew()
return
}
@ -124,12 +123,24 @@ func mouseMove(g *gocui.Gui) {
}
}
func (tk *guiWidget) setAsDragging() {
me.mouse.currentDrag = tk
tk.lastW = tk.gocuiSize.w0
tk.lastH = tk.gocuiSize.h0
}
// this is how the window gets dragged around
func (tk *guiWidget) moveNew() {
w, h := me.baseGui.MousePosition()
if tk.node.WidgetType == widget.Window {
tk.window.wasDragged = true
tk.redrawWindow(w-tk.dragW, h-tk.dragH) // TODO: fix these hard coded things with offsets
// compute the new location based off how far the mouse has moved
// since the mouse button was pressed down
newW := tk.lastW + w - me.mouse.downW
newH := tk.lastH + h - me.mouse.downH
tk.redrawWindow(newW, newH)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
return
}
@ -151,12 +162,11 @@ func (tk *guiWidget) moveNew() {
// me.stdout.lastH = h - me.stdout.mouseOffsetH
tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
} else {
// tk.dumpWidget(fmt.Sprintf("move(%dx%d) %s", w, h, tk.cuiName))
// log.Info("Resize false", w, h)
// me.stdout.lastW = w - me.stdout.mouseOffsetW
// me.stdout.lastH = h - me.stdout.mouseOffsetH
// tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
tk.relocateStdout(w-tk.dragW, h-tk.dragH)
// compute the new location based off how far the mouse has moved
// since the mouse button was pressed down
newW := tk.lastW + w - me.mouse.downW
newH := tk.lastH + h - me.mouse.downH
tk.relocateStdout(newW, newH)
}
}
// always place the help menu on top

View File

@ -135,8 +135,6 @@ func (r *rectType) Height() int {
type window struct {
windowFrame *guiWidget // this is the frame for a window widget
wasDragged bool // indicates the window was dragged. This keeps it from being rearranged
dragW int // when dragging a window, this is the offset to the mouse position
dragH int // when dragging a window, this is the offset to the mouse position
hasTabs bool // does the window have tabs?
currentTab bool // the visible tab
selectedTab *tree.Node // for a window, this is currently selected tab
@ -165,8 +163,6 @@ type guiWidget struct {
node *tree.Node // the pointer back to the tree
windowFrame *guiWidget // this is the frame for a window widget
internal bool // indicates the widget is internal to gocui and should be treated differently
dragW int // when dragging a window, this is the offset to the mouse position
dragH int // when dragging a window, this is the offset to the mouse position
hasTabs bool // does the window have tabs?
currentTab bool // the visible tab
window window // holds information specific only to Window widgets
@ -180,6 +176,8 @@ type guiWidget struct {
force rectType // force widget within these boundries (using this to debug window dragging)
startW int // ?
startH int // ?
lastW int // used during mouse dragging
lastH int // used during mouse dragging
isFake bool // widget types like 'box' are 'false'
widths map[int]int // how tall each row in the grid is
heights map[int]int // how wide each column in the grid is
@ -189,7 +187,6 @@ type guiWidget struct {
color *colorT // what color to use
defaultColor *colorT // the default colors // TODO: make a function for this instead
isBG bool // means this is the background widget. There is only one of these
// resize bool // the window is currently being resized
}
// THIS IS GO COMPILER MAGIC