From 93e87a05c7220f1a8dd7ac2e8dc43b123f6e0f71 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 6 Feb 2025 14:46:32 -0600 Subject: [PATCH] dragging a windows keeps it put --- eventMouseMove.go | 1 + structs.go | 1 + window.go | 21 ++++++++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/eventMouseMove.go b/eventMouseMove.go index 980612f..adce6ed 100644 --- a/eventMouseMove.go +++ b/eventMouseMove.go @@ -105,6 +105,7 @@ func mouseMove(g *gocui.Gui) { 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 setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn return diff --git a/structs.go b/structs.go index 1a8ed5b..e57c69a 100644 --- a/structs.go +++ b/structs.go @@ -119,6 +119,7 @@ func (r *rectType) Height() int { // settings that are window specific 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? diff --git a/window.go b/window.go index 313c153..621bae1 100644 --- a/window.go +++ b/window.go @@ -83,13 +83,24 @@ func (tk *guiWidget) redrawWindow(w int, h int) { // re-draws the buttons for each of the windows func redoWindows(nextW int, nextH int) { - for _, win := range findWindows() { - win.dumpWidget(fmt.Sprintf("redoWindowsS (%d,%d)", nextW, nextH)) - win.redrawWindow(nextW, nextH) - win.dumpWidget(fmt.Sprintf("redoWindowsE (%d,%d)", nextW, nextH)) + for _, tk := range findWindows() { + tk.dumpWidget(fmt.Sprintf("redoWindowsS (%d,%d)", nextW, nextH)) + if tk.window.wasDragged { + // don't move windows around the user has dragged to a certain location + tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0) + } else { + w, _ := me.baseGui.Size() + if nextW > w-20 { + nextW = 0 + nextH += 4 + } + // probably a new window? + tk.redrawWindow(nextW, nextH) + } + tk.dumpWidget(fmt.Sprintf("redoWindowsE (%d,%d)", nextW, nextH)) // increment the width for the next window - nextW += win.gocuiSize.Width() + 10 + nextW += tk.gocuiSize.Width() + 10 // nextH += 10 } }