2025-02-01 11:42:31 -06:00
|
|
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the GPL 3.0
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-28 02:20:31 -06:00
|
|
|
|
2025-02-05 07:24:14 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
2024-01-18 00:08:37 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-18 04:10:08 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
2024-01-28 14:03:06 -06:00
|
|
|
func (w *guiWidget) dumpTree(s string) {
|
2025-01-31 12:08:13 -06:00
|
|
|
// log.Log(ERROR, "dump w", w.node.WidgetId, w.WidgetType, w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
if w == nil {
|
2025-02-01 15:15:05 -06:00
|
|
|
log.Log(ERROR, "dump w.TK == nil", w.node.WidgetId, w.node.WidgetType, w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2025-02-01 13:43:51 -06:00
|
|
|
w.dumpWidget("dumpTree() " + s)
|
2024-01-18 00:08:37 -06:00
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range w.children {
|
2024-01-28 14:03:06 -06:00
|
|
|
child.dumpTree(s)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-05 15:55:56 -06:00
|
|
|
func (w *guiWidget) dumpWindows(s string) {
|
|
|
|
// log.Log(ERROR, "dump w", w.node.WidgetId, w.WidgetType, w.String())
|
|
|
|
if w == nil {
|
|
|
|
log.Log(ERROR, "dump w.TK == nil", w.node.WidgetId, w.node.WidgetType, w.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if w.node.WidgetType == widget.Window {
|
2025-02-05 16:30:06 -06:00
|
|
|
s += fmt.Sprintf(" F(%d,%d)", w.force.w0, w.force.h0)
|
|
|
|
// can't set this here. doesn't work
|
|
|
|
// w.full.w0 = w.force.w0
|
|
|
|
// w.full.h0 = w.force.h0
|
2025-02-05 15:55:56 -06:00
|
|
|
w.dumpWidget("dumpWindow() " + s)
|
2025-02-05 16:30:06 -06:00
|
|
|
w.windowFrame.dumpWidget("dumpFrame() " + s)
|
2025-02-05 15:55:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.dumpWindows(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-01 13:43:51 -06:00
|
|
|
// a standard function to print out information about a widget
|
2025-02-03 10:55:50 -06:00
|
|
|
func (tk *guiWidget) dumpWidget(s string) {
|
2024-01-18 00:08:37 -06:00
|
|
|
var s1 string
|
|
|
|
var pId int
|
2025-02-04 15:48:14 -06:00
|
|
|
// tk.verifyRect()
|
2025-02-03 10:55:50 -06:00
|
|
|
if tk.node.Parent == nil {
|
2025-02-05 07:24:14 -06:00
|
|
|
log.Logf(WARN, "showWidgetPlacement() parent == nil wId=%d cuiName=%s", tk.node.WidgetId, tk.cuiName)
|
2024-01-18 00:08:37 -06:00
|
|
|
pId = 0
|
|
|
|
} else {
|
2025-02-03 10:55:50 -06:00
|
|
|
pId = tk.node.Parent.WidgetId
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2025-02-03 10:55:50 -06:00
|
|
|
s1 = fmt.Sprintf("(wId,pId)=(%4d,%4d) ", tk.node.WidgetId, pId)
|
|
|
|
sizeW, sizeH := tk.Size()
|
2025-02-06 19:00:00 -06:00
|
|
|
hide := "S"
|
|
|
|
if tk.Hidden() {
|
|
|
|
hide = "H"
|
|
|
|
}
|
|
|
|
s1 += fmt.Sprintf("size=(%3d,%3d)%s)", sizeW, sizeH, hide)
|
2025-02-03 10:55:50 -06:00
|
|
|
if tk.Visible() {
|
2025-01-31 12:08:13 -06:00
|
|
|
s1 += fmt.Sprintf("gocui=(%3d,%3d,%3d,%3d)",
|
2025-02-03 10:55:50 -06:00
|
|
|
tk.gocuiSize.w0, tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1)
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2025-01-31 12:08:13 -06:00
|
|
|
s1 += fmt.Sprintf(" %3s %3s %3s %3s ", "", "", "", "")
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2025-02-04 15:48:14 -06:00
|
|
|
s1 += fmt.Sprintf(" full=(%3d,%3d,%3d,%3d)", tk.full.w0, tk.full.h0, tk.full.w1, tk.full.h1)
|
2025-02-03 10:55:50 -06:00
|
|
|
if tk.node.Parent != nil {
|
|
|
|
if tk.node.Parent.WidgetType == widget.Grid {
|
2025-02-06 19:34:26 -06:00
|
|
|
s1 += fmt.Sprintf("At(%3d,%3d)", tk.node.State.AtW, tk.node.State.AtH)
|
|
|
|
s1 += fmt.Sprintf("(%3d,%3d) ", tk.parent.widths[tk.node.State.AtW], tk.parent.heights[tk.node.State.AtH])
|
2025-01-29 07:55:56 -06:00
|
|
|
} else {
|
2025-02-06 19:34:26 -06:00
|
|
|
s1 += fmt.Sprintf(" %3s %3s ", "", "")
|
|
|
|
s1 += fmt.Sprintf(" %3s %3s ", "", "")
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2025-01-29 07:55:56 -06:00
|
|
|
} else {
|
2025-01-31 12:08:13 -06:00
|
|
|
s1 += fmt.Sprintf(" %3s %3s ", "", "")
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2025-01-31 12:08:13 -06:00
|
|
|
var end string
|
2025-02-03 10:55:50 -06:00
|
|
|
if tk.node.WidgetType == widget.Box {
|
2025-02-06 14:19:43 -06:00
|
|
|
end = fmt.Sprintf("%-8s %-8s %s", tk.node.WidgetType, tk.cuiName, tk.node.State.Direction.String())
|
2025-01-31 12:08:13 -06:00
|
|
|
} else {
|
2025-02-03 10:55:50 -06:00
|
|
|
curval := tk.String()
|
2025-02-02 13:06:30 -06:00
|
|
|
if curval == "" {
|
2025-02-03 10:55:50 -06:00
|
|
|
curval = tk.node.GetLabel()
|
2025-02-02 13:06:30 -06:00
|
|
|
}
|
2025-02-06 14:19:43 -06:00
|
|
|
end = fmt.Sprintf("%-8s %-8s %s", tk.node.WidgetType, tk.cuiName, tk.String())
|
2024-02-05 04:28:42 -06:00
|
|
|
}
|
2025-02-05 07:24:14 -06:00
|
|
|
log.Log(GOCUI, s1, s, end)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printWidgetTree(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
me.treeRoot.ListWidgets()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func printWidgetPlacements(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
w := me.treeRoot.TK.(*guiWidget)
|
|
|
|
w.dumpTree("MM")
|
2025-02-05 15:55:56 -06:00
|
|
|
w.dumpWindows("WW")
|
2025-02-05 07:24:14 -06:00
|
|
|
return nil
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|