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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
package main
import (
// "os"
"os"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/widget"
"go.wit.com/toolkits/tree"
)
// This routine is very specific to this toolkit
// It's annoying and has to be copied to each widget when there are changes
// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten
// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here!
// but it's time to write direct GTK, QT, macos and windows toolkit plugins
// -- jcarr 2023/03/09
// Grid numbering examples by (X,Y)
// ---------
// -- (1) --
// -- (2) --
// ---------
//
// -----------------------------
// -- (1,1) -- (1,2) -- (1,3) --
// -- (2,1) -- (2,2) -- (2,3) --
// -----------------------------
// internally for andlabs/ui
// (x&y flipped and start at zero)
// -----------------------------
// -- (0,0) -- (1,0) -- (1,0) --
// -- (0,1) -- (1,1) -- (1,1) --
// -----------------------------
func place(p *tree.Node, n *tree.Node) bool {
// log.Log(INFO, "place() 1 START", n.WidgetType, n.GetProgName(), n.GetLabel())
if p == nil {
log.Log(WARN, "place() parent == nil")
os.Exit(-1)
return false
}
if n == nil {
log.Log(WARN, "place() node == nil")
os.Exit(-1)
return false
}
if !ready(n) {
if n.WidgetType == widget.Window {
// TODO: figure out window in window placement
return true
}
log.Log(ERROR, "place() 1 START not ready()", n.WidgetType, n.GetProgName(), n.GetLabel())
return false
}
var tk, ptk *guiWidget
tk = n.TK.(*guiWidget)
ptk = p.TK.(*guiWidget)
if ptk == nil {
log.Log(ERROR, "ptk == nil", p.GetProgName(), p.ParentId, p.WidgetType, ptk)
log.Log(ERROR, "n = ", n.GetProgName(), n.ParentId, n.WidgetType, tk)
log.Log(ERROR, "SPEEDY ptk == nil", n.WidgetId, n.GetProgName())
log.Sleep(1)
panic("ptk == nil")
}
// p.DumpWidget("parent: ")
// n.DumpWidget("child: ")
// log.Log(WARN, "place() switch", p.WidgetType, n.WidgetId, n.GetProgName())
switch p.WidgetType {
case widget.Grid:
tk.gridX = n.State.GridOffset.X - 1
tk.gridY = n.State.GridOffset.Y - 1
// log.Log(WARN, "place() on Grid at gridX,gridY", tk.gridX, tk.gridY)
ptk.uiGrid.Append(tk.uiControl,
tk.gridX, tk.gridY, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
return true
case widget.Group:
if ptk.uiBox == nil {
log.Log(ANDLABS, "place() andlabs hack group to use add a box", n.GetProgName(), n.WidgetType)
n.State.Direction = widget.Vertical
ptk.uiBox = rawBox(n)
ptk.uiGroup.SetChild(ptk.uiBox)
}
if n.WidgetType == widget.Textbox {
ptk.uiBox.Append(tk.uiControl, true)
} else {
ptk.uiBox.Append(tk.uiControl, n.State.Expand)
}
return true
case widget.Tab:
if ptk.uiTab == nil {
log.Log(ERROR, "ptk.uiTab == nil for n.WidgetId =", n.WidgetId, "ptk =", ptk)
panic("ptk.uiTab == nil")
}
if tk.uiControl == nil {
log.Log(ERROR, "tk.uiControl == nil for n.WidgetId =", n.WidgetId, "tk =", tk)
panic("tk.uiControl == nil")
}
log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab")
ptk.uiTab.Append(n.State.Label, tk.uiControl)
ptk.boxC += 1
return true
case widget.Box:
log.Log(INFO, "place() uiBox =", ptk.uiBox)
log.Log(INFO, "place() uiControl =", tk.uiControl)
if n.WidgetType == widget.Textbox {
ptk.uiBox.Append(tk.uiControl, true)
} else {
ptk.uiBox.Append(tk.uiControl, n.State.Expand)
}
ptk.boxC += 1
return true
case widget.Window:
log.Log(INFO, "Adding Something to Window", n.WidgetId, n.GetProgName())
if n.WidgetType == widget.Window {
log.Log(INFO, "TODO: make window in a window a tab", n.WidgetId, n.GetProgName())
return true
}
ptk.uiWindow.SetChild(tk.uiControl)
return true
default:
log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType)
}
log.Log(ERROR, "newplace() returned without doing anything", n.WidgetId, n.GetProgName())
return false
}
|