summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eventBindings.go22
-rw-r--r--eventMouse.go1
-rw-r--r--eventMouseClick.go13
-rw-r--r--find.go35
-rw-r--r--structs.go16
-rw-r--r--treeDraw.go2
-rw-r--r--window.go23
7 files changed, 66 insertions, 46 deletions
diff --git a/eventBindings.go b/eventBindings.go
index 166696e..ea91904 100644
--- a/eventBindings.go
+++ b/eventBindings.go
@@ -96,18 +96,6 @@ func addDropdown() *tree.Node {
func theNotsure(g *gocui.Gui, v *gocui.View) error {
log.Info("got keypress 2. now what?")
log.Info("try to switch windows here")
- if len(me.allwin) != len(findWindows()) {
- me.allwin = findWindows()
- }
- newwin := findNextWindow()
- for i, win := range me.allwin {
- log.Info("Window", i, "named", win.labelN, win.activeWindow)
- }
- if newwin == nil {
- log.Info("findNextWindow() err. returned nil")
- return nil
- }
- newwin.doWidgetClick(newwin.gocuiSize.w0, newwin.gocuiSize.h0)
return nil
}
@@ -116,15 +104,13 @@ func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
if len(me.allwin) != len(findWindows()) {
me.allwin = findWindows()
}
- newwin := findNextWindow()
- for i, win := range me.allwin {
- log.Info("Window", i, "named", win.labelN, win.activeWindow)
- }
- if newwin == nil {
+ tk := findNextWindow()
+ if tk == nil {
log.Info("findNextWindow() err. returned nil")
return nil
}
- newwin.doWidgetClick(newwin.gocuiSize.w0, newwin.gocuiSize.h0)
+ tk.makeWindowActive()
+ tk.doWidgetClick(tk.gocuiSize.w0, tk.gocuiSize.h0)
return nil
}
diff --git a/eventMouse.go b/eventMouse.go
index c8d3fca..37698dc 100644
--- a/eventMouse.go
+++ b/eventMouse.go
@@ -62,6 +62,7 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
log.Info("mouseDown() nothing to click on at", w, h)
return nil
}
+ tk.makeWindowActive()
log.Info("SENDING mouseDown() to findWindowUnderMouse()")
if tk.node.WidgetType == widget.Window {
// check to see if this is a direct click on a widget
diff --git a/eventMouseClick.go b/eventMouseClick.go
index 5990f27..a04c992 100644
--- a/eventMouseClick.go
+++ b/eventMouseClick.go
@@ -20,7 +20,6 @@ func (tk *guiWidget) doWindowClick(w int, h int) {
// now set this window as the current window
me.currentWindow = tk
me.currentWindow.isCurrent = true
- tk.active = false
tk.redrawWindow(w, h)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
@@ -35,18 +34,6 @@ func (tk *guiWidget) doWidgetClick(w int, h int) {
tk.doWindowClick(w, h)
return
case widget.Group:
- /*
- if tk.active {
- tk.active = false
- tk.placeWidgets(tk.startW, tk.startH)
- tk.showWidgets()
- } else {
- tk.active = true
- for _, child := range tk.children {
- child.hideWidgets()
- }
- }
- */
case widget.Checkbox:
if tk.node.State.Checked {
log.Log(WARN, "checkbox is being set to false")
diff --git a/find.go b/find.go
index 434a42d..6833b9a 100644
--- a/find.go
+++ b/find.go
@@ -5,6 +5,7 @@ package main
import (
"fmt"
+ "slices"
"github.com/awesome-gocui/gocui"
log "go.wit.com/log"
@@ -111,23 +112,21 @@ func (tk *guiWidget) findBG() *guiWidget {
return nil
}
+// used by gocui.TabKey to rotate through the windows
func findNextWindow() *guiWidget {
var found bool
if len(me.allwin) == 0 {
return nil
}
- for _, win := range me.allwin {
- if win.activeWindow {
+ for _, tk := range me.allwin {
+ if tk.window.active {
found = true
- win.activeWindow = false
continue
}
if found {
- win.activeWindow = true
- return win
+ return tk
}
}
- me.allwin[0].activeWindow = true
// at the end, loop to the beginning
return me.allwin[0]
}
@@ -147,17 +146,31 @@ func findWindowUnderMouse() *guiWidget {
}
}
+ // print out the window list
+ for _, tk := range me.allwin {
+ log.Info("findWindowUnderMouse() print:", tk.labelN, tk.window.active, tk.window.order)
+ }
+
// now check if the active window is below the mouse
- 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
+ for _, tk := range me.allwin {
+ if tk.window.active {
+ if tk.full.inRect(w, h) {
+ log.Info(fmt.Sprintf("findWindowUnderMouse() found %s active window (%dx%d)", tk.cuiName, w, h))
+ return tk
}
}
}
// well, just find any window then
+ // sorting by order might work?
+ slices.SortFunc(me.allwin, func(a, b *guiWidget) int {
+ return a.window.order - b.window.order
+ })
+
+ // print out the window list
+ for _, tk := range me.allwin {
+ log.Info("findWindowUnderMouse() print:", tk.labelN, tk.window.active, tk.window.order)
+ }
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))
diff --git a/structs.go b/structs.go
index 7f9bf65..21a2d71 100644
--- a/structs.go
+++ b/structs.go
@@ -116,6 +116,19 @@ func (r *rectType) Height() int {
return r.h1 - r.h0
}
+// settings that are window specific
+type window struct {
+ windowFrame *guiWidget // this is the frame for a window widget
+ 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
+ active bool // means this window is the active one
+ isBG bool // means this is the background widget. There is only one of these
+ order int // what level the window is on
+}
+
type guiWidget struct {
v *gocui.View // this is nil if the widget is not displayed
cuiName string // what gocui uses to reference the widget (usually "TK <widgetId>"
@@ -128,11 +141,11 @@ type guiWidget struct {
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
value string // ?
checked bool // ?
labelN string // the actual text to display in the console
vals []string // dropdown menu items
- active bool // ?
enable bool // ?
defaultColor *colorT // store the color to go back to
gocuiSize rectType // should mirror the real display size. todo: verify these are accurate. they are not yet
@@ -150,7 +163,6 @@ type guiWidget struct {
color *colorT // what color to use
resize bool // the window is currently being resized
isBG bool // means this is the background widget. There is only one of these
- activeWindow bool // means this window is the active one
}
// from the gocui devs:
diff --git a/treeDraw.go b/treeDraw.go
index fd3fdaa..c876ee5 100644
--- a/treeDraw.go
+++ b/treeDraw.go
@@ -106,13 +106,11 @@ func (tk *guiWidget) drawView() {
func (w *guiWidget) DrawAt(offsetW, offsetH int) {
w.setColor(&colorActiveW)
w.placeWidgets(offsetW, offsetH) // compute the sizes & places for each widget
- w.active = false
// w.dumpWidget(fmt.Sprintf("DrawAt(%d,%d)", offsetW, offsetH))
}
func (w *guiWidget) simpleDrawAt(offsetW, offsetH int) {
w.setColor(&colorActiveW)
- w.active = false
w.dumpWidget("simpleDrawAt()")
}
diff --git a/window.go b/window.go
index 1039430..a13970e 100644
--- a/window.go
+++ b/window.go
@@ -6,6 +6,7 @@ package main
import (
"fmt"
+ log "go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
@@ -125,3 +126,25 @@ func (win *guiWidget) addWindowFrame(wId int) *tree.Node {
n.TK = tk
return n
}
+
+func (tk *guiWidget) makeWindowActive() {
+ if !(tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Stdout) {
+ // only allow Window or the Stdout widgets to be made active
+ return
+ }
+
+ // disable and increment all the windows
+ for _, tk := range me.allwin {
+ tk.window.order += 1
+ tk.window.active = false
+ }
+
+ // set this window as the active one
+ tk.window.active = true
+ tk.window.order = 0
+
+ // print out the window list
+ for _, tk := range me.allwin {
+ log.Info("makeWindowActive() Window", tk.labelN, tk.window.active, tk.window.order)
+ }
+}