debugging cleanups

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-09 03:45:03 -06:00
parent 9dd8a8afc9
commit 7b611d3dda
6 changed files with 58 additions and 45 deletions

View File

@ -13,15 +13,15 @@ func (w *guiWidget) doWidgetClick() {
/* /*
case widget.Root: case widget.Root:
// THIS IS THE BEGINING OF THE LAYOUT // THIS IS THE BEGINING OF THE LAYOUT
log.Log(NOW, "doWidgetClick()", w.String()) log.Log(GOCUI, "doWidgetClick()", w.String())
wRoot := me.treeRoot.TK.(*guiWidget) wRoot := me.treeRoot.TK.(*guiWidget)
wRoot.redoWindows(0, 0) wRoot.redoWindows(0, 0)
case widget.Flag: case widget.Flag:
log.Log(NOW, "doWidgetClick() FLAG widget name =", w.String()) log.Log(GOCUI, "doWidgetClick() FLAG widget name =", w.String())
log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") log.Log(GOCUI, "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(GOCUI, "doWidgetClick() START on window", w.String())
// if the user clicked on the current window, do nothing // if the user clicked on the current window, do nothing
/* Ignore this for now and redraw the window anyway /* Ignore this for now and redraw the window anyway
if me.currentWindow == w { if me.currentWindow == w {
@ -43,7 +43,7 @@ func (w *guiWidget) doWidgetClick() {
me.currentWindow.isCurrent = true me.currentWindow.isCurrent = true
// draw the current window // draw the current window
log.Log(NOW, "doWidgetClick() set currentWindow to", w.String()) log.Log(GOCUI, "doWidgetClick() set currentWindow to", w.String())
w.setColor(&colorActiveW) w.setColor(&colorActiveW)
w.DrawAt(3, 2) w.DrawAt(3, 2)
w.placeWidgets(3, 2) // compute the sizes & places for each widget w.placeWidgets(3, 2) // compute the sizes & places for each widget
@ -88,9 +88,9 @@ func (w *guiWidget) doWidgetClick() {
case widget.Box: case widget.Box:
// w.showWidgetPlacement(logNow, "drawTree()") // w.showWidgetPlacement(logNow, "drawTree()")
if w.node.State.Direction == widget.Horizontal { if w.node.State.Direction == widget.Horizontal {
log.Log(NOW, "BOX IS HORIZONTAL", w.String()) log.Log(GOCUI, "BOX IS HORIZONTAL", w.String())
} else { } else {
log.Log(NOW, "BOX IS VERTICAL", w.String()) log.Log(GOCUI, "BOX IS VERTICAL", w.String())
} }
w.placeWidgets(w.startW, w.startH) w.placeWidgets(w.startW, w.startH)
w.toggleTree() w.toggleTree()
@ -98,11 +98,11 @@ func (w *guiWidget) doWidgetClick() {
// doUserEvent(n) // doUserEvent(n)
me.myTree.SendFromUser(w.node) me.myTree.SendFromUser(w.node)
case widget.Combobox: case widget.Combobox:
log.Log(NOW, "do the combobox here") log.Log(GOCUI, "do the combobox here")
w.showDropdown() w.showDropdown()
me.dropdownW = w me.dropdownW = w
case widget.Dropdown: case widget.Dropdown:
log.Log(NOW, "do the dropdown here") log.Log(GOCUI, "do the dropdown here")
w.showDropdown() w.showDropdown()
me.dropdownW = w me.dropdownW = w
default: default:
@ -112,7 +112,7 @@ func (w *guiWidget) doWidgetClick() {
func click(g *gocui.Gui, v *gocui.View) error { func click(g *gocui.Gui, v *gocui.View) error {
mouseW, mouseH := me.baseGui.MousePosition() mouseW, mouseH := me.baseGui.MousePosition()
log.Log(NOW, "click() START gocui name:", v.Name()) log.Log(GOCUI, "click() START gocui name:", v.Name())
w := findUnderMouse() w := findUnderMouse()
// if the dropdown view is visable, process it no matter what // if the dropdown view is visable, process it no matter what
@ -126,7 +126,7 @@ func click(g *gocui.Gui, v *gocui.View) error {
if w == nil { if w == nil {
log.Error(errors.New("click() could not find widget for view =" + v.Name())) log.Error(errors.New("click() could not find widget for view =" + v.Name()))
} else { } else {
log.Log(NOW, "click() Found widget =", w.node.WidgetId, w.String(), ",", w.labelN) log.Log(GOCUI, "click() Found widget =", w.node.WidgetId, w.String(), ",", w.labelN)
w.doWidgetClick() w.doWidgetClick()
} }
@ -134,7 +134,7 @@ func click(g *gocui.Gui, v *gocui.View) error {
realTK := rootTK.findWidgetByView(v) realTK := rootTK.findWidgetByView(v)
if realTK == nil { if realTK == nil {
log.Error(errors.New("toolkit click() out of reality with gocui. v.Name() not in binary tree " + v.Name())) log.Error(errors.New("toolkit click() out of reality with gocui. v.Name() not in binary tree " + v.Name()))
log.Log(NOW, "click() END FAILURE ON gocui v.Name =", v.Name()) log.Log(GOCUI, "click() END FAILURE ON gocui v.Name =", v.Name())
// return nil // otherwise gocui exits // return nil // otherwise gocui exits
} }
@ -145,19 +145,19 @@ func click(g *gocui.Gui, v *gocui.View) error {
return nil return nil
} }
if nameTK.v == nil { if nameTK.v == nil {
log.Log(NOW, "click() maybe this widget has had it's view distroyed?", nameTK.cuiName, nameTK.WidgetType) log.Log(GOCUI, "click() maybe this widget has had it's view distroyed?", nameTK.cuiName, nameTK.WidgetType)
log.Log(NOW, "yep. it's gone now") log.Log(GOCUI, "yep. it's gone now")
return nil return nil
} }
// SetCurrentView dies if it's sent an non-existent view // SetCurrentView dies if it's sent an non-existent view
if _, err := g.SetCurrentView(v.Name()); err != nil { if _, err := g.SetCurrentView(v.Name()); err != nil {
log.Log(NOW, "click() END v.Name =", v.Name(), "err =", err) log.Log(GOCUI, "click() END v.Name =", v.Name(), "err =", err)
// return err // return causes gocui.MainLoop() to exit. Do we ever want that to happen here? // return err // return causes gocui.MainLoop() to exit. Do we ever want that to happen here?
return nil return nil
} }
log.Log(NOW, "click() END gocui name:", v.Name()) log.Log(GOCUI, "click() END gocui name:", v.Name())
return nil return nil
} }
@ -186,7 +186,6 @@ func findUnderMouse() *guiWidget {
var found *guiWidget var found *guiWidget
// widgets has everything that matches // widgets has everything that matches
for _, w := range widgets { for _, w := range widgets {
w.showWidgetPlacement("findUnderMouse() FOUND")
// prioritize window buttons. This means if some code covers // prioritize window buttons. This means if some code covers
// up the window widgets, then it will ignore everything else // up the window widgets, then it will ignore everything else
// and allow the user (hopefully) to redraw or switch windows // and allow the user (hopefully) to redraw or switch windows
@ -194,6 +193,7 @@ func findUnderMouse() *guiWidget {
if w.WidgetType == widget.Window { if w.WidgetType == widget.Window {
return w return w
} }
// w.showWidgetPlacement("findUnderMouse() FOUND")
found = w found = w
} }
return found return found

View File

@ -73,16 +73,16 @@ func (tk *guiWidget) showDropdown() {
// var items []string // var items []string
// items = tk.node.State.Strings // items = tk.node.State.Strings
//for i, s := range items { //for i, s := range items {
for i, s := range tk.vals { for i, s := range tk.node.Strings() {
log.Log(NOW, "showDropdown()", tk.String(), i, s) log.Log(GOCUI, "showDropdown()", tk.String(), i, s)
ddItems += s + "\n" ddItems += s + "\n"
} }
log.Log(NOW, "new dropdown items should be set to:", ddItems) log.Log(GOCUI, "new dropdown items should be set to:", ddItems)
sizeW, sizeH := tk.Size() sizeW, sizeH := tk.Size()
log.Log(NOW, "showDropdown() size W,H=", sizeW, sizeH) log.Log(GOCUI, "showDropdown() size W,H=", sizeW, sizeH)
startW, startH := tk.Position() startW, startH := tk.Position()
log.Log(NOW, "showDropdown() location W,H=", startW, startH) log.Log(GOCUI, "showDropdown() location W,H=", startW, startH)
me.dropdownV.MoveToOffset(startW+3, startH+2) me.dropdownV.MoveToOffset(startW+3, startH+2)
me.dropdownV.labelN = ddItems me.dropdownV.labelN = ddItems
me.dropdownV.Show() me.dropdownV.Show()
@ -90,7 +90,7 @@ func (tk *guiWidget) showDropdown() {
func hideDDview() error { func hideDDview() error {
w, h := me.baseGui.MousePosition() w, h := me.baseGui.MousePosition()
log.Log(NOW, "hide dropdown menu() view msgMouseDown (w,h) =", w, h) log.Log(GOCUI, "hide dropdown menu() view msgMouseDown (w,h) =", w, h)
if me.dropdownV == nil { if me.dropdownV == nil {
return gocui.ErrUnknownView return gocui.ErrUnknownView
} }
@ -103,7 +103,7 @@ func hideDDview() error {
func showDDview() error { func showDDview() error {
w, h := me.baseGui.MousePosition() w, h := me.baseGui.MousePosition()
log.Log(NOW, "show dropdown menu() view msgMouseDown (w,h) =", w, h) log.Log(GOCUI, "show dropdown menu() view msgMouseDown (w,h) =", w, h)
if me.dropdownV == nil { if me.dropdownV == nil {
return gocui.ErrUnknownView return gocui.ErrUnknownView
} }
@ -119,21 +119,21 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string {
w.Hide() w.Hide()
startW, startH := w.Position() startW, startH := w.Position()
log.Log(NOW, "dropdownClicked() start (w,h) =", startW, startH) log.Log(GOCUI, "dropdownClicked() start (w,h) =", startW, startH)
log.Log(NOW, "dropdownClicked() at (w,h) =", mouseW, mouseH) log.Log(GOCUI, "dropdownClicked() at (w,h) =", mouseW, mouseH)
itemNumber := mouseH - startH itemNumber := mouseH - startH
items := strings.Split(w.labelN, "\n") items := strings.Split(w.labelN, "\n")
log.Log(NOW, "dropdownClicked() look for item", itemNumber, "len(items) =", len(items)) log.Log(GOCUI, "dropdownClicked() look for item", itemNumber, "len(items) =", len(items))
if itemNumber < 1 { if itemNumber < 1 {
return "" return ""
} }
if len(items) >= itemNumber { if len(items) >= itemNumber {
log.Log(NOW, "dropdownClicked() found", items[itemNumber-1]) log.Log(GOCUI, "dropdownClicked() found", items[itemNumber-1])
if items[itemNumber-1] != "" { if items[itemNumber-1] != "" {
if me.dropdownW != nil { if me.dropdownW != nil {
log.Log(NOW, "dropdownClicked() send event for", me.dropdownW.cuiName, me.dropdownW.WidgetType) log.Log(GOCUI, "dropdownClicked() send event for", me.dropdownW.cuiName, me.dropdownW.WidgetType)
me.dropdownW.SetText(items[itemNumber-1]) me.dropdownW.SetText(items[itemNumber-1])
me.dropdownW.node.SetCurrentS(items[itemNumber-1]) me.dropdownW.node.SetCurrentS(items[itemNumber-1])
me.myTree.SendUserEvent(me.dropdownW.node) me.myTree.SendUserEvent(me.dropdownW.node)
@ -146,11 +146,11 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string {
func dropdownUnclicked(mouseX, mouseH int) { func dropdownUnclicked(mouseX, mouseH int) {
if me.dropdownV == nil { if me.dropdownV == nil {
log.Log(NOW, "mouseUp() dropdownV = nil", mouseX, mouseH) log.Log(GOCUI, "mouseUp() dropdownV = nil", mouseX, mouseH)
return return
} }
tk := me.dropdownV tk := me.dropdownV
log.Log(NOW, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", mouseX, mouseH) log.Log(GOCUI, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", mouseX, mouseH)
log.Log(NOW, "mouseUp() ddview is the thing that was clicked", mouseX, mouseH) log.Log(GOCUI, "mouseUp() ddview is the thing that was clicked", mouseX, mouseH)
log.Log(NOW, "mouseUp() find out what the string is here", mouseX, mouseH, tk.gocuiSize.h1) log.Log(GOCUI, "mouseUp() find out what the string is here", mouseX, mouseH, tk.gocuiSize.h1)
} }

8
log.go
View File

@ -12,6 +12,7 @@ var outputS []string
var NOW *log.LogFlag var NOW *log.LogFlag
var INFO *log.LogFlag var INFO *log.LogFlag
var GOCUI *log.LogFlag
var SPEW *log.LogFlag var SPEW *log.LogFlag
var WARN *log.LogFlag var WARN *log.LogFlag
@ -19,9 +20,14 @@ var WARN *log.LogFlag
var ERROR *log.LogFlag var ERROR *log.LogFlag
func init() { func init() {
full := "go.wit.com/toolkits/gocui" full := "go.wit.com/gui"
short := "gocui" short := "gocui"
GOCUI = log.NewFlag("GOCUI", false, full, short, "gocui internals")
full = "go.wit.com/toolkits/gocui"
short = "gocui"
NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")
INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff") INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff")

View File

@ -27,7 +27,7 @@ func mouseMove(g *gocui.Gui) {
func msgDown(g *gocui.Gui, v *gocui.View) error { func msgDown(g *gocui.Gui, v *gocui.View) error {
initialMouseX, initialMouseY = g.MousePosition() initialMouseX, initialMouseY = g.MousePosition()
log.Log(NOW, "msgDown() X,Y", initialMouseX, initialMouseY) log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY)
if vx, vy, _, _, err := g.ViewPosition("msg"); err == nil { if vx, vy, _, _, err := g.ViewPosition("msg"); err == nil {
xOffset = initialMouseX - vx xOffset = initialMouseX - vx
yOffset = initialMouseY - vy yOffset = initialMouseY - vy
@ -73,7 +73,7 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
} else if x+len(msg)+1 > maxX-1 { } else if x+len(msg)+1 > maxX-1 {
x = maxX - 1 - len(msg) - 1 x = maxX - 1 - len(msg) - 1
} }
log.Log(NOW, "mouseDown() about to write out message to 'globalDown' view. msg =", msg) log.Log(GOCUI, "mouseDown() about to write out message to 'globalDown' view. msg =", msg)
if v, err := g.SetView("globalDown", x, my-1, x+len(msg)+1, my+1, 0); err != nil { if v, err := g.SetView("globalDown", x, my-1, x+len(msg)+1, my+1, 0); err != nil {
if !errors.Is(err, gocui.ErrUnknownView) { if !errors.Is(err, gocui.ErrUnknownView) {
return err return err

View File

@ -86,10 +86,8 @@ func newaction(n *tree.Node, atype widget.ActionType) {
w := n.TK.(*guiWidget) w := n.TK.(*guiWidget)
switch atype { switch atype {
case widget.Show: case widget.Show:
log.Log(NOW, "Show() HERE. a.Hidden() was =", n.Hidden())
w.Show() w.Show()
case widget.Hide: case widget.Hide:
log.Log(NOW, "Hide() HERE. a.State.Hidden was =", n.Hidden())
w.Hide() w.Hide()
case widget.Move: case widget.Move:
log.Log(NOW, "attempt to move() =", atype, n.WidgetType, n.ProgName()) log.Log(NOW, "attempt to move() =", atype, n.WidgetType, n.ProgName())

View File

@ -65,7 +65,7 @@ func setupCtrlDownWidget() {
func (w *guiWidget) deleteView() { func (w *guiWidget) deleteView() {
// make sure the view isn't really there // make sure the view isn't really there
log.Log(NOW, "deleteView()", w.cuiName, w.WidgetType, w.node.WidgetId) log.Log(GOCUI, "deleteView()", w.cuiName, w.WidgetType, w.node.WidgetId)
me.baseGui.DeleteView(w.cuiName) me.baseGui.DeleteView(w.cuiName)
w.v = nil w.v = nil
} }
@ -75,8 +75,8 @@ func (w *guiWidget) IsCurrent() bool {
return w.isCurrent return w.isCurrent
} }
if w.node.WidgetType == widget.Window { if w.node.WidgetType == widget.Window {
log.Log(NOW, "IsCurrent() found current window", w.cuiName, w.String()) log.Log(GOCUI, "IsCurrent() found current window", w.cuiName, w.String())
log.Log(NOW, "IsCurrent() window w.isCurrent =", w.isCurrent) log.Log(GOCUI, "IsCurrent() window w.isCurrent =", w.isCurrent)
return w.isCurrent return w.isCurrent
} }
if w.node.WidgetType == widget.Root { if w.node.WidgetType == widget.Root {
@ -125,15 +125,24 @@ func (w *guiWidget) Show() {
return return
} }
if w.node.WidgetType == widget.Dropdown {
log.Log(NOW, "Show() dropdown", w.cuiName, w.String())
log.Log(NOW, "Show() dropdown n.Strings() =", w.node.Strings())
}
if w.node.WidgetType == widget.Combobox {
log.Log(NOW, "Show() dropdown", w.cuiName, w.String())
log.Log(NOW, "Show() dropdown n.Strings() =", w.node.Strings())
}
// if the widget is not in the current displayed windo // if the widget is not in the current displayed windo
// then ignore it // then ignore it
log.Log(NOW, "Show() widget =", w.cuiName, w.String()) log.Log(GOCUI, "Show() widget =", w.cuiName, w.String())
log.Log(NOW, "Show() w.IsCurrent() returned", w.IsCurrent()) log.Log(GOCUI, "Show() w.IsCurrent() returned", w.IsCurrent())
if !w.IsCurrent() { if !w.IsCurrent() {
log.Log(NOW, "Show() NOT drawing", w.cuiName, w.String()) log.Log(GOCUI, "Show() NOT drawing", w.cuiName, w.String())
return return
} }
log.Log(NOW, "Show() drawing", w.cuiName, w.String()) log.Log(GOCUI, "Show() drawing", w.cuiName, w.String())
// finally, check if the widget State is hidden or not // finally, check if the widget State is hidden or not
if w.node.Hidden() { if w.node.Hidden() {