summaryrefslogtreecommitdiff
path: root/debug.go
blob: 0e3ae94854e56a96fc2bc82e022140826c360ec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"

	"github.com/awesome-gocui/gocui"
	"go.wit.com/log"
	"go.wit.com/widget"
)

func (w *guiWidget) dumpTree(s string) {
	// log.Log(ERROR, "dump w", w.WidgetId(), w.WidgetType, w.String())
	if w == nil {
		log.Log(ERROR, "dump w.TK == nil", w.WidgetId(), w.WidgetType(), w.String())
		return
	}
	w.dumpWidget("dumpTree() " + s)

	for _, child := range w.children {
		child.dumpTree(s)
	}
}

func (w *guiWidget) dumpWindows(s string) {
	// log.Log(ERROR, "dump w", w.WidgetId(), w.WidgetType, w.String())
	if w == nil {
		log.Log(ERROR, "dump w.TK == nil", w.WidgetId(), w.WidgetType(), w.String())
		return
	}
	if w.WidgetType() == widget.Window {
		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
		w.dumpWidget("dumpWindow() " + s)
		w.windowFrame.dumpWidget("dumpFrame() " + s)
	}

	for _, child := range w.children {
		child.dumpWindows(s)
	}
}

// a standard function to print out information about a widget
func (tk *guiWidget) dumpWidget(s string) {
	var s1 string
	var pId int
	// tk.verifyRect()
	if tk.parent == nil {
		log.Logf(WARN, "showWidgetPlacement() parent == nil wId=%d cuiName=%s", tk.WidgetId(), tk.cuiName)
		pId = 0
	} else {
		pId = tk.parent.WidgetId()
	}
	s1 = fmt.Sprintf("(wId,pId)=(%4d,%4d) ", tk.WidgetId(), pId)
	sizeW, sizeH := tk.Size()
	hide := "S"
	if tk.Hidden() {
		hide = "H"
	}
	s1 += fmt.Sprintf("size=(%3d,%3d)%s)", sizeW, sizeH, hide)
	if tk.Visible() {
		s1 += fmt.Sprintf("gocui=(%3d,%3d,%3d,%3d)",
			tk.gocuiSize.w0, tk.gocuiSize.h0, tk.gocuiSize.w1, tk.gocuiSize.h1)
	} else {
		s1 += fmt.Sprintf("       %3s %3s %3s %3s ", "", "", "", "")
	}
	s1 += fmt.Sprintf(" full=(%3d,%3d,%3d,%3d)", tk.full.w0, tk.full.h0, tk.full.w1, tk.full.h1)
	if tk.parent != nil {
		if tk.parent.WidgetType() == widget.Grid {
			s1 += fmt.Sprintf("At(%3d,%3d)", tk.GridW(), tk.GridH())
			s1 += fmt.Sprintf("(%3d,%3d) ", tk.parent.widths[tk.GridW()], tk.parent.heights[tk.GridH()])
		} else {
			s1 += fmt.Sprintf("   %3s %3s ", "", "")
			s1 += fmt.Sprintf(" %3s %3s  ", "", "")
		}
	} else {
		s1 += fmt.Sprintf("   %3s %3s  ", "", "")
	}
	var end string
	if tk.WidgetType() == widget.Box {
		end = fmt.Sprintf("%-8s %-8s %s %s", tk.WidgetType(), tk.cuiName, tk.Direction().String(), tk.String())
	} else {
		end = fmt.Sprintf("%-8s %-8s %s", tk.WidgetType(), tk.cuiName, tk.String())
	}
	if tk.node.InTable() {
		// log.Log(GOCUI, "findParentTAble()", tk.labelN, tk.cuiName, tk.node.WidgetId)
		end += " (table)"
	}
	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")
	w.dumpWindows("WW")
	return nil
}