set the node.State.Label on SetText()

This commit is contained in:
Jeff Carr 2025-02-05 07:24:14 -06:00
parent a81e931b9a
commit 12f3d5ac5c
5 changed files with 67 additions and 44 deletions

View File

@ -6,6 +6,7 @@ package main
import (
"fmt"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/widget"
)
@ -29,7 +30,7 @@ func (tk *guiWidget) dumpWidget(s string) {
var pId int
// tk.verifyRect()
if tk.node.Parent == nil {
log.Log(INFO, "showWidgetPlacement() parent == nil", tk.node.WidgetId, tk.cuiName)
log.Logf(WARN, "showWidgetPlacement() parent == nil wId=%d cuiName=%s", tk.node.WidgetId, tk.cuiName)
pId = 0
} else {
pId = tk.node.Parent.WidgetId
@ -63,5 +64,30 @@ func (tk *guiWidget) dumpWidget(s string) {
}
end = fmt.Sprintf("%5s %-8s %s", tk.cuiName, tk.node.WidgetType, tk.String())
}
log.Log(NOW, s1, s, end)
log.Log(GOCUI, s1, s, end)
}
func printWidgetTree(g *gocui.Gui, v *gocui.View) error {
me.treeRoot.ListWidgets()
tk := me.logStdout
// msg := fmt.Sprintf("test out kb %d\n", ecount)
// tk.Write([]byte(msg))
if tk == nil {
log.Log(ERROR, "tk = nil")
}
if tk.v == nil {
log.Log(ERROR, "tk.v = nil")
} else {
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
log.CaptureMode(tk)
}
return nil
}
func printWidgetPlacements(g *gocui.Gui, v *gocui.View) error {
w := me.treeRoot.TK.(*guiWidget)
w.dumpTree("MM")
return nil
}

View File

@ -65,6 +65,9 @@ func addDropdownNew(wId int) *tree.Node {
tk.labelN = "DropBox text"
tk.node = n
if tk.node.Parent == nil {
tk.node.Parent = me.treeRoot
}
// copy the data from the action message
tk.node.State.Label = "DropBox"

View File

@ -38,14 +38,14 @@ func registerHandlers(g *gocui.Gui) {
g.SetKeybinding("", 'q', gocui.ModNone, doExit) // 'q' exit
// debugging
g.SetKeybinding("", 'f', gocui.ModNone, theFind) // 'f' shows what is under your mouse
g.SetKeybinding("", 'S', gocui.ModNone, setSuperMouse) // 'S' Super Mouse mode!
g.SetKeybinding("", 'h', gocui.ModNone, theHide) // 'h' hide all widgets
g.SetKeybinding("", 'M', gocui.ModNone, dumpWidgetPlacement) // 'M' list all widgets with positions
g.SetKeybinding("", 'L', gocui.ModNone, dumpWidgets) // 'L' list all widgets in tree view
g.SetKeybinding("", 'd', gocui.ModNone, theLetterD) // 'd' toggles on and off debugging buttons
g.SetKeybinding("", '2', gocui.ModNone, theNotsure) // '2' for testing new ideas
g.SetKeybinding("", 'q', gocui.ModNone, quit) // 'q' only exits gocui. plugin stays alive (?)
g.SetKeybinding("", 'f', gocui.ModNone, theFind) // 'f' shows what is under your mouse
g.SetKeybinding("", 'S', gocui.ModNone, setSuperMouse) // 'S' Super Mouse mode!
g.SetKeybinding("", 'h', gocui.ModNone, theHide) // 'h' hide all widgets
g.SetKeybinding("", 'M', gocui.ModNone, printWidgetPlacements) // 'M' list all widgets with positions
g.SetKeybinding("", 'L', gocui.ModNone, printWidgetTree) // 'L' list all widgets in tree view
g.SetKeybinding("", 'd', gocui.ModNone, theLetterD) // 'd' toggles on and off debugging buttons
g.SetKeybinding("", '2', gocui.ModNone, theNotsure) // '2' for testing new ideas
g.SetKeybinding("", 'q', gocui.ModNone, quit) // 'q' only exits gocui. plugin stays alive (?)
}
// flips on 'super mouse' mode
@ -152,6 +152,7 @@ func theNotsure(g *gocui.Gui, v *gocui.View) error {
if notsure == nil {
// notsure = makeDropdownView("addWidget() notsure")
notsure = addDropdownTK(-118)
notsure.node.State.Label = "apple/pear"
notsure.makeTK([]string{"apple", "pear"})
}
notsure.MoveToOffset(w+2, h+1)
@ -197,31 +198,6 @@ func doPanic(g *gocui.Gui, v *gocui.View) error {
panic("forced panic in gocui")
}
func dumpWidgets(g *gocui.Gui, v *gocui.View) error {
me.treeRoot.ListWidgets()
tk := me.logStdout
// msg := fmt.Sprintf("test out kb %d\n", ecount)
// tk.Write([]byte(msg))
if tk == nil {
log.Log(ERROR, "tk = nil")
}
if tk.v == nil {
log.Log(ERROR, "tk.v = nil")
} else {
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
log.CaptureMode(tk)
}
return nil
}
func dumpWidgetPlacement(g *gocui.Gui, v *gocui.View) error {
w := me.treeRoot.TK.(*guiWidget)
w.dumpTree("MM")
return nil
}
func openDebuggger(g *gocui.Gui, v *gocui.View) error {
me.myTree.SendEnableDebugger()
return nil

View File

@ -4,6 +4,7 @@
package main
import (
"fmt"
"strings"
"go.wit.com/log"
@ -86,14 +87,24 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
return startW, startH
case widget.Tab:
case widget.Grid:
tk.dumpWidget(fmt.Sprintf("PlaceGridS(%d,%d)", startW, startH))
// reset the widths and heights maps here
tk.widths = make(map[int]int) // how tall each row in the grid is
tk.heights = make(map[int]int) // how wide each column in the grid is
newW, newH := tk.placeGrid(startW, startH)
tk.full.w0 = newW
tk.full.h0 = newH
tk.full.w1 = newW
tk.full.h1 = newH
tk.dumpWidget(fmt.Sprintf("PlaceGridE(%d,%d)", newW, newH))
return newW, newH
case widget.Box:
tk.placeBox(startW, startH)
tk.full.w0 = startW
tk.full.h0 = startH
tk.full.w1 = startW
tk.full.h1 = startH
tk.dumpWidget(fmt.Sprintf("PlaceBox(%d,%d)", startW, startH))
return 0, 0
case widget.Stdout:
tk.setStdoutWH(startW, startH)
@ -103,6 +114,8 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
tk.gocuiSetWH(startW, startH)
tk.full.w0 = startW
tk.full.h0 = startH
tk.full.w1 = startW
tk.full.h1 = startH
newW := startW + me.GroupPadW
newH := startH + 1 // normal hight of the group label
@ -121,7 +134,9 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
}
log.Log(INFO, "REAL HEIGHT sizeW:", sizeW, "sizeH:", sizeH)
}
return maxW, newH - startH
newH = newH - startH
tk.dumpWidget(fmt.Sprintf("PlaceGroup(%d,%d)", maxW, newH))
return maxW, newH
default:
tk.gocuiSetWH(startW, startH)
return tk.gocuiSize.Width(), tk.gocuiSize.Height()
@ -188,6 +203,8 @@ func (w *guiWidget) placeGrid(startW int, startH int) (int, int) {
// child.showWidgetPlacement("grid2:")
}
// w.showWidgetPlacement("grid3:")
w.full.w1 = startW + maxW
w.full.h1 = startH + maxH
return maxW, maxH
}

View File

@ -161,23 +161,24 @@ func (w *guiWidget) AddText(text string) {
w.SetText(text)
}
func (w *guiWidget) SetText(text string) {
func (tk *guiWidget) SetText(text string) {
var changed bool = false
if w == nil {
if tk == nil {
log.Log(NOW, "widget is nil")
return
}
if w.labelN != text {
w.labelN = text
if tk.labelN != text {
tk.labelN = text
changed = true
}
tk.node.State.Label = text
if !changed {
return
}
if w.Visible() {
w.textResize()
w.Hide()
w.Show()
if tk.Visible() {
tk.textResize()
tk.Hide()
tk.Show()
}
}