window depth order works

This commit is contained in:
Jeff Carr 2025-02-06 13:47:19 -06:00
parent 9fa974f6c4
commit 88f33afbb7
7 changed files with 66 additions and 46 deletions

View File

@ -96,18 +96,6 @@ func addDropdown() *tree.Node {
func theNotsure(g *gocui.Gui, v *gocui.View) error { func theNotsure(g *gocui.Gui, v *gocui.View) error {
log.Info("got keypress 2. now what?") log.Info("got keypress 2. now what?")
log.Info("try to switch windows here") 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 return nil
} }
@ -116,15 +104,13 @@ func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
if len(me.allwin) != len(findWindows()) { if len(me.allwin) != len(findWindows()) {
me.allwin = findWindows() me.allwin = findWindows()
} }
newwin := findNextWindow() tk := findNextWindow()
for i, win := range me.allwin { if tk == nil {
log.Info("Window", i, "named", win.labelN, win.activeWindow)
}
if newwin == nil {
log.Info("findNextWindow() err. returned nil") log.Info("findNextWindow() err. returned nil")
return nil return nil
} }
newwin.doWidgetClick(newwin.gocuiSize.w0, newwin.gocuiSize.h0) tk.makeWindowActive()
tk.doWidgetClick(tk.gocuiSize.w0, tk.gocuiSize.h0)
return nil return nil
} }

View File

@ -62,6 +62,7 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
log.Info("mouseDown() nothing to click on at", w, h) log.Info("mouseDown() nothing to click on at", w, h)
return nil return nil
} }
tk.makeWindowActive()
log.Info("SENDING mouseDown() to findWindowUnderMouse()") log.Info("SENDING mouseDown() to findWindowUnderMouse()")
if tk.node.WidgetType == widget.Window { if tk.node.WidgetType == widget.Window {
// check to see if this is a direct click on a widget // check to see if this is a direct click on a widget

View File

@ -20,7 +20,6 @@ func (tk *guiWidget) doWindowClick(w int, h int) {
// now set this window as the current window // now set this window as the current window
me.currentWindow = tk me.currentWindow = tk
me.currentWindow.isCurrent = true me.currentWindow.isCurrent = true
tk.active = false
tk.redrawWindow(w, h) tk.redrawWindow(w, h)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn 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) tk.doWindowClick(w, h)
return return
case widget.Group: 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: case widget.Checkbox:
if tk.node.State.Checked { if tk.node.State.Checked {
log.Log(WARN, "checkbox is being set to false") log.Log(WARN, "checkbox is being set to false")

35
find.go
View File

@ -5,6 +5,7 @@ package main
import ( import (
"fmt" "fmt"
"slices"
"github.com/awesome-gocui/gocui" "github.com/awesome-gocui/gocui"
log "go.wit.com/log" log "go.wit.com/log"
@ -111,23 +112,21 @@ func (tk *guiWidget) findBG() *guiWidget {
return nil return nil
} }
// used by gocui.TabKey to rotate through the windows
func findNextWindow() *guiWidget { func findNextWindow() *guiWidget {
var found bool var found bool
if len(me.allwin) == 0 { if len(me.allwin) == 0 {
return nil return nil
} }
for _, win := range me.allwin { for _, tk := range me.allwin {
if win.activeWindow { if tk.window.active {
found = true found = true
win.activeWindow = false
continue continue
} }
if found { if found {
win.activeWindow = true return tk
return win
} }
} }
me.allwin[0].activeWindow = true
// at the end, loop to the beginning // at the end, loop to the beginning
return me.allwin[0] 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 // now check if the active window is below the mouse
for _, win := range me.allwin { for _, tk := range me.allwin {
if win.activeWindow { if tk.window.active {
if win.full.inRect(w, h) { if tk.full.inRect(w, h) {
log.Info(fmt.Sprintf("findWindowUnderMouse() found %s active window (%dx%d)", win.cuiName, w, h)) log.Info(fmt.Sprintf("findWindowUnderMouse() found %s active window (%dx%d)", tk.cuiName, w, h))
return win return tk
} }
} }
} }
// well, just find any window then // 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 { for _, win := range me.allwin {
if win.full.inRect(w, h) { if win.full.inRect(w, h) {
log.Info(fmt.Sprintf("findWindowUnderMouse() found %s window (%dx%d)", win.cuiName, w, h)) log.Info(fmt.Sprintf("findWindowUnderMouse() found %s window (%dx%d)", win.cuiName, w, h))

View File

@ -116,6 +116,19 @@ func (r *rectType) Height() int {
return r.h1 - r.h0 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 { type guiWidget struct {
v *gocui.View // this is nil if the widget is not displayed v *gocui.View // this is nil if the widget is not displayed
cuiName string // what gocui uses to reference the widget (usually "TK <widgetId>" 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 dragH int // when dragging a window, this is the offset to the mouse position
hasTabs bool // does the window have tabs? hasTabs bool // does the window have tabs?
currentTab bool // the visible tab currentTab bool // the visible tab
window window // holds information specific only to Window widgets
value string // ? value string // ?
checked bool // ? checked bool // ?
labelN string // the actual text to display in the console labelN string // the actual text to display in the console
vals []string // dropdown menu items vals []string // dropdown menu items
active bool // ?
enable bool // ? enable bool // ?
defaultColor *colorT // store the color to go back to 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 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 color *colorT // what color to use
resize bool // the window is currently being resized resize bool // the window is currently being resized
isBG bool // means this is the background widget. There is only one of these 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: // from the gocui devs:

View File

@ -106,13 +106,11 @@ func (tk *guiWidget) drawView() {
func (w *guiWidget) DrawAt(offsetW, offsetH int) { func (w *guiWidget) DrawAt(offsetW, offsetH int) {
w.setColor(&colorActiveW) w.setColor(&colorActiveW)
w.placeWidgets(offsetW, offsetH) // compute the sizes & places for each widget w.placeWidgets(offsetW, offsetH) // compute the sizes & places for each widget
w.active = false
// w.dumpWidget(fmt.Sprintf("DrawAt(%d,%d)", offsetW, offsetH)) // w.dumpWidget(fmt.Sprintf("DrawAt(%d,%d)", offsetW, offsetH))
} }
func (w *guiWidget) simpleDrawAt(offsetW, offsetH int) { func (w *guiWidget) simpleDrawAt(offsetW, offsetH int) {
w.setColor(&colorActiveW) w.setColor(&colorActiveW)
w.active = false
w.dumpWidget("simpleDrawAt()") w.dumpWidget("simpleDrawAt()")
} }

View File

@ -6,6 +6,7 @@ package main
import ( import (
"fmt" "fmt"
log "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
) )
@ -125,3 +126,25 @@ func (win *guiWidget) addWindowFrame(wId int) *tree.Node {
n.TK = tk n.TK = tk
return n 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)
}
}