-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
83 lines (73 loc) · 1.68 KB
/
debug.go
File metadata and controls
83 lines (73 loc) · 1.68 KB
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
package gui
import (
"fmt"
"github.com/maxfish/GoNativeUI-Core/utils"
"reflect"
"strings"
)
func ColorToString(f utils.Color) string {
return fmt.Sprintf("{%.2f,%.2f,%.2f,%.2f}", f[0], f[1], f[2], f[3])
}
func InsetsToString(i utils.Insets) string {
return fmt.Sprintf("{top:%d,right:%d,bottom:%d,left:%d}", i.Top, i.Right, i.Bottom, i.Left)
}
func WidgetToDebugString(str interface{}) string {
widget := str.(IWidget)
// Widget id
wId := ""
if widget.Id() != "" {
wId = " '" + widget.Id() + "'"
}
// Struct type
wType := ""
switch str.(type) {
case *Container:
wType = "C"
case *BoxContainer:
wType = "BC"
case *Label:
wType = "L"
case *Button:
wType = "B"
default:
wType = strings.Replace(reflect.TypeOf(widget).String(), "*gui.", "", -1)
}
// Flags
flags := ""
if widget.Enabled() {
flags += "E"
}
if widget.Visible() {
flags += "V"
}
// Extra content
extra := ""
switch w := str.(type) {
case *Label:
extra = "text:\"" + w.text + "\""
case *Button:
extra = "text:\"" + w.text + "\""
}
return fmt.Sprintf("(%s)%s %s %s %s", wType, wId, widget.Bounds().ToString(), flags, extra)
}
func ContainerToTreeDebugString(c IContainer) string {
return containerToTreeDebugString(c, "")
}
func containerToTreeDebugString(node IWidget, depth string) string {
s := WidgetToDebugString(node) + "\n"
container, ok := node.(IContainer)
if ok {
for index, _ := range container.Children() {
child := container.Children()[index]
s += fmt.Sprintf("%s `--", depth)
c := " "
if index < container.ChildrenCount()-1 {
c = "|"
}
depth += " " + c + " "
s += containerToTreeDebugString(child, depth)
depth = depth[:len(depth)-4]
}
}
return s
}