cleaner debugging

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-28 13:14:43 -06:00
parent 44ee09f798
commit dab898f0f9
7 changed files with 56 additions and 58 deletions

2
add.go
View File

@ -80,5 +80,5 @@ func addWidget(n *tree.Node) {
} }
*/ */
} }
nw.showWidgetPlacement(true, "addWidget()") nw.showWidgetPlacement("addWidget()")
} }

View File

@ -101,6 +101,7 @@ func (w *guiWidget) doWidgetClick() {
log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?")
case widget.Window: case widget.Window:
log.Log(NOW, "doWidgetClick() START on window", w.String()) log.Log(NOW, "doWidgetClick() START on window", w.String())
/*
if me.currentWindow == w.node { if me.currentWindow == w.node {
return return
} }
@ -111,13 +112,19 @@ func (w *guiWidget) doWidgetClick() {
curw.setColor(&colorWindow) curw.setColor(&colorWindow)
curw.hideWidgets() curw.hideWidgets()
} }
*/
me.currentWindow = w.node me.currentWindow = w.node
log.Log(NOW, "doWidgetClick() set currentWindow to", w.String()) log.Log(NOW, "doWidgetClick() set currentWindow to", w.String())
w.setColor(&colorActiveW) w.setColor(&colorActiveW)
w.hideWidgets() if w.active {
w.active = false
w.placeWidgets(me.RawW, me.RawH) w.placeWidgets(me.RawW, me.RawH)
w.showWidgets() w.showWidgets()
} else {
w.active = true
w.hideWidgets()
}
/* /*
w.redoTabs(me.TabW, me.TabH) w.redoTabs(me.TabW, me.TabH)
for _, child := range w.children { for _, child := range w.children {
@ -158,7 +165,22 @@ func (w *guiWidget) doWidgetClick() {
w.showWidgets() w.showWidgets()
case widget.Group: case widget.Group:
// n.placeWidgets(p.tk.startH, newH) // n.placeWidgets(p.tk.startH, newH)
w.toggleTree() if w.active {
w.active = false
startW := me.RawW
startH := me.RawH
for _, child := range w.children {
log.Log(INFO, "START W,H", startW, startH)
child.placeWidgets(me.RawW, me.RawH)
child.showWidgets()
}
} else {
w.active = true
for _, child := range w.children {
child.hideWidgets()
}
}
w.dumpTree()
case widget.Checkbox: case widget.Checkbox:
if widget.GetBool(w.value) { if widget.GetBool(w.value) {
w.setCheckbox(false) w.setCheckbox(false)
@ -255,7 +277,7 @@ func (w *guiWidget) drawTree(draw bool) {
if w == nil { if w == nil {
return return
} }
w.showWidgetPlacement(true, "drawTree()") w.showWidgetPlacement("drawTree()")
if draw { if draw {
// w.textResize() // w.textResize()
w.showView() w.showView()
@ -344,7 +366,7 @@ func findUnderMouse() *tree.Node {
for _, n := range widgets { for _, n := range widgets {
//log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name) //log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name)
widget := n.TK.(*guiWidget) widget := n.TK.(*guiWidget)
widget.showWidgetPlacement(true, "findUnderMouse() FOUND") widget.showWidgetPlacement("findUnderMouse() FOUND")
} }
return found return found
} }
@ -381,6 +403,6 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
} else { } else {
// me.ctrlDown.showView() // me.ctrlDown.showView()
} }
// me.ctrlDown.showWidgetPlacement(true, "ctrlDown:") // me.ctrlDown.showWidgetPlacement("ctrlDown:")
return nil return nil
} }

View File

@ -7,20 +7,20 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func (w *guiWidget) dumpTree(draw bool) { func (w *guiWidget) dumpTree() {
// log.Log(ERROR, "dumpTree w", w.node.WidgetId, w.WidgetType, w.String()) // log.Log(ERROR, "dumpTree w", w.node.WidgetId, w.WidgetType, w.String())
if w == nil { if w == nil {
log.Log(ERROR, "dumpTree w.TK == nil", w.node.WidgetId, w.WidgetType, w.String()) log.Log(ERROR, "dumpTree w.TK == nil", w.node.WidgetId, w.WidgetType, w.String())
return return
} }
w.showWidgetPlacement(true, "dumpTree()") w.showWidgetPlacement("dumpTree()")
for _, child := range w.children { for _, child := range w.children {
child.dumpTree(draw) child.dumpTree()
} }
} }
func (w *guiWidget) showWidgetPlacement(b bool, s string) { func (w *guiWidget) showWidgetPlacement(s string) {
var s1 string var s1 string
var pId int var pId int
if w.node.Parent == nil { if w.node.Parent == nil {
@ -45,29 +45,3 @@ func (w *guiWidget) showWidgetPlacement(b bool, s string) {
tmp := "." + w.String() + "." tmp := "." + w.String() + "."
log.Log(INFO, s1, s, w.node.WidgetType, ",", tmp, "jcarr") // , "text=", w.text) log.Log(INFO, s1, s, w.node.WidgetType, ",", tmp, "jcarr") // , "text=", w.text)
} }
/*
func dumpWidget(n *tree.Node, pad string) {
log.Log(NOW, "node:", pad, n.WidgetId, "At(", n.AtW, n.AtH, ") ,", n.WidgetType, ", n.progname =", n.progname, ", n.label =", n.label)
}
*/
/*
func listWidgets(n *tree.Node) {
if n == nil {
return
}
var pad string
for i := 0; i < me.depth; i++ {
pad = pad + " "
}
n.dumpWidget(pad)
for _, child := range n.children {
me.depth += 1
child.listWidgets()
me.depth -= 1
}
return
}
*/

View File

@ -119,7 +119,7 @@ func addDebugKeys(g *gocui.Gui) {
g.SetKeybinding("", 'M', gocui.ModNone, g.SetKeybinding("", 'M', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error { func(g *gocui.Gui, v *gocui.View) error {
w := me.treeRoot.TK.(*guiWidget) w := me.treeRoot.TK.(*guiWidget)
w.dumpTree(true) w.dumpTree()
return nil return nil
}) })

View File

@ -12,13 +12,13 @@ func (tk *guiWidget) placeBox(startW int, startH int) {
if tk.WidgetType != widget.Box { if tk.WidgetType != widget.Box {
return return
} }
tk.showWidgetPlacement(true, "boxS()") tk.showWidgetPlacement("boxS()")
newW := startW newW := startW
newH := startH newH := startH
for _, child := range tk.children { for _, child := range tk.children {
child.placeWidgets(newW, newH) child.placeWidgets(newW, newH)
// n.showWidgetPlacement(logNow, "boxS()") // n.showWidgetPlacement("boxS()")
newR := child.realGocuiSize() newR := child.realGocuiSize()
w := newR.w1 - newR.w0 w := newR.w1 - newR.w0
h := newR.h1 - newR.h0 h := newR.h1 - newR.h0
@ -36,7 +36,7 @@ func (tk *guiWidget) placeBox(startW int, startH int) {
// just compute this every time? // just compute this every time?
// newR := n.realGocuiSize() // newR := n.realGocuiSize()
tk.showWidgetPlacement(true, "boxE()") tk.showWidgetPlacement("boxE()")
} }
func (tk *guiWidget) placeWidgets(startW int, startH int) { func (tk *guiWidget) placeWidgets(startW int, startH int) {
@ -65,7 +65,7 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) {
case widget.Group: case widget.Group:
// move the group to the parent's next location // move the group to the parent's next location
tk.gocuiSetWH(startW, startH) tk.gocuiSetWH(startW, startH)
tk.showWidgetPlacement(true, "group()") tk.showWidgetPlacement("group()")
newW := startW + me.GroupPadW newW := startW + me.GroupPadW
newH := startH + 3 // normal hight of the group label newH := startH + 3 // normal hight of the group label
@ -86,7 +86,7 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) {
} }
func (w *guiWidget) placeGrid(startW int, startH int) { func (w *guiWidget) placeGrid(startW int, startH int) {
w.showWidgetPlacement(true, "grid0:") w.showWidgetPlacement("grid0:")
if w.WidgetType != widget.Grid { if w.WidgetType != widget.Grid {
return return
} }
@ -104,13 +104,13 @@ func (w *guiWidget) placeGrid(startW int, startH int) {
if w.heights[child.AtH] < childH { if w.heights[child.AtH] < childH {
w.heights[child.AtH] = childH w.heights[child.AtH] = childH
} }
// child.showWidgetPlacement(logInfo, "grid: ") // child.showWidgetPlacement("grid: ")
log.Log(INFO, "placeGrid:", child.String(), "child()", childW, childH, "At()", child.AtW, child.AtH) log.Log(INFO, "placeGrid:", child.String(), "child()", childW, childH, "At()", child.AtW, child.AtH)
} }
// find the width and height offset of the grid for AtW,AtH // find the width and height offset of the grid for AtW,AtH
for _, child := range w.children { for _, child := range w.children {
child.showWidgetPlacement(true, "grid1:") child.showWidgetPlacement("grid1:")
var totalW, totalH int var totalW, totalH int
for i, w := range w.widths { for i, w := range w.widths {
@ -130,9 +130,9 @@ func (w *guiWidget) placeGrid(startW int, startH int) {
log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH) log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH)
child.placeWidgets(newW, newH) child.placeWidgets(newW, newH)
child.showWidgetPlacement(true, "grid2:") child.showWidgetPlacement("grid2:")
} }
w.showWidgetPlacement(true, "grid3:") w.showWidgetPlacement("grid3:")
} }
// computes the real, actual size of all the gocli objects in a widget // computes the real, actual size of all the gocli objects in a widget

View File

@ -143,6 +143,8 @@ type guiWidget struct {
vals []string // dropdown menu items vals []string // dropdown menu items
active bool
AtW int AtW int
AtH int AtH int

20
view.go
View File

@ -42,7 +42,7 @@ func (w *guiWidget) textResize() bool {
changed = true changed = true
} }
if changed { if changed {
w.showWidgetPlacement(true, "textResize() changed") w.showWidgetPlacement("textResize() changed")
} }
return changed return changed
} }
@ -123,10 +123,10 @@ func (w *guiWidget) recreateView() {
w.v = nil w.v = nil
if w.String() == "CLOUDFLARE_EMAIL" { if w.String() == "CLOUDFLARE_EMAIL" {
w.showWidgetPlacement(true, "n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName) w.showWidgetPlacement("n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName)
// w.dumpWidget("jwc") // w.dumpWidget("jwc")
w.textResize() w.textResize()
w.showWidgetPlacement(true, "n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName) w.showWidgetPlacement("n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName)
} }
a := w.gocuiSize.w0 a := w.gocuiSize.w0
@ -136,12 +136,12 @@ func (w *guiWidget) recreateView() {
w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0) w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0)
if err == nil { if err == nil {
w.showWidgetPlacement(true, "recreateView()") w.showWidgetPlacement("recreateView()")
log.Log(ERROR, "recreateView() internal plugin error err = nil") log.Log(ERROR, "recreateView() internal plugin error err = nil")
return return
} }
if !errors.Is(err, gocui.ErrUnknownView) { if !errors.Is(err, gocui.ErrUnknownView) {
w.showWidgetPlacement(true, "recreateView()") w.showWidgetPlacement("recreateView()")
log.Log(ERROR, "recreateView() internal plugin error error.IS()", err) log.Log(ERROR, "recreateView() internal plugin error error.IS()", err)
return return
} }
@ -161,7 +161,7 @@ func (w *guiWidget) recreateView() {
w.v.Frame = w.frame w.v.Frame = w.frame
w.v.Clear() w.v.Clear()
fmt.Fprint(w.v, w.labelN) fmt.Fprint(w.v, w.labelN)
// n.showWidgetPlacement(true, "n.String()=" + n.String() + " n.tk.label=" + n.tk.label + " " + w.cuiName) // n.showWidgetPlacement("n.String()=" + n.String() + " n.tk.label=" + n.tk.label + " " + w.cuiName)
// n.dumpWidget("jwc 2") // n.dumpWidget("jwc 2")
// if you don't do this here, it will be black & white only // if you don't do this here, it will be black & white only
@ -173,8 +173,8 @@ func (w *guiWidget) recreateView() {
w.v.SelBgColor = w.color.selBg w.v.SelBgColor = w.color.selBg
} }
if w.String() == "CLOUDFLARE_EMAIL" { if w.String() == "CLOUDFLARE_EMAIL" {
w.showWidgetPlacement(true, "w.String()="+w.String()+" w.label="+w.labelN+" "+w.cuiName) w.showWidgetPlacement("w.String()="+w.String()+" w.label="+w.labelN+" "+w.cuiName)
w.dumpTree(true) w.dumpTree()
} }
log.Log(ERROR, "recreateView() END") log.Log(ERROR, "recreateView() END")
} }
@ -208,7 +208,7 @@ func (w *guiWidget) showFake() {
if w.isFake { if w.isFake {
// w.setFake() // w.setFake()
w.showView() w.showView()
w.showWidgetPlacement(true, "showFake:") w.showWidgetPlacement("showFake:")
} }
for _, child := range w.children { for _, child := range w.children {
child.showFake() child.showFake()
@ -219,7 +219,7 @@ func (w *guiWidget) showWidgets() {
if w.isFake { if w.isFake {
// don't display by default // don't display by default
} else { } else {
w.showWidgetPlacement(true, "current:") w.showWidgetPlacement("current:")
w.showView() w.showView()
} }
for _, child := range w.children { for _, child := range w.children {