forked from jk3064/chiliui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_chiliguidemo.lua
363 lines (322 loc) · 9.94 KB
/
gui_chiliguidemo.lua
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "chiliGUIDemo",
desc = "GUI demo for robocracy",
author = "quantum",
date = "WIP",
license = "WIP",
layer = 1,
enabled = false -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- gui elements
local window0
local window01
local gridWindow0
local gridWindow1
local windowImageList
local window1
local window2
local window3
function widget:Initialize()
Chili = WG.Chili
local function ToggleOrientation(self)
local panel = self:FindParent"layoutpanel"
panel.orientation = ((panel.orientation == "horizontal") and "vertical") or "horizontal"
panel:UpdateClientArea()
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local testText =
[[Bolivians are voting in a referendum on a new constitution that President Evo Morales says will empower the country's indigenous majority.
The changes also include strengthening state control of Bolivia's natural resources, and no longer recognising Catholicism as the official religion.
The constitution is widely expected to be approved.
Mr Morales, an Aymara Indian, has pursued political reform but has met fierce resistance from some sectors.
Opponents concentrated in Bolivia's eastern provinces, which hold rich gas deposits, argue that the new constitution would create two classes of citizenship - putting indigenous people ahead of others.
The wrangling has spilled over into, at times, deadly violence. At least 30 peasant farmers were ambushed and killed on their way home from a pro-government rally in a northern region in September.
President Morales has said the new constitution will pave the way for correcting the historic inequalities of Bolivian society, where the economic elite is largely of European descent.
]]
local testText2 =
"\255\001\255\250Bolivians\b are voting in a referendum on a \255\255\255\000new\b constitution "
local testText3 =
[[Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod]]
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local cs = {
Chili.Button:New{
x = 20,
y = 20,
},
Chili.Label:New{
x = 20,
y = 50,
caption= 'FOOBAR',
},
Chili.ScrollPanel:New{
backgroundColor = {0,0,0,0.5},
children = {
Chili.Button:New{caption="foo", width = 100, height = 100},
}
},
Chili.Checkbox:New{
x = 20,
y = 70,
caption = 'foo',
},
Chili.Trackbar:New{
x = 20,
y = 90,
},
Chili.Colorbars:New{
x = 20,
y = 120,
},
Chili.ComboBox:New{items = { "opt1", "opt2", "opt3", "opt4", "opt5", "opt6", "opt7", "opt8", "opt9", "opt10", "opt11", "opt12", }},
}
window0 = Chili.Window:New{
x = 200,
y = 450,
width = 200,
height = 200,
parent = Chili.Screen0,
children = {
Chili.StackPanel:New{
height = "100%";
width = "100%";
weightedResize = true;
children = {
Chili.Button:New{caption="height: 70%", weight = 7; width = "90%"},
Chili.Button:New{caption="height: 30%", weight = 3},
};
}
},
}
local btn0 = Chili.Button:New{
caption = "Dispose Me",
name = "btn_dispose_me1",
}
btn0:Dispose()
-- we need a container that supports margin if the control inside uses margins
window01 = Chili.Window:New{
x = 200,
y = 200,
clientWidth = 200,
clientHeight = 200,
parent = Chili.Screen0,
}
local panel1 = Chili.StackPanel:New{
width = 200,
height = 200,
--resizeItems = false,
x=0, right=0,
y=0, bottom=0,
margin = {10, 10, 10, 10},
parent = window01,
children = cs,
}
local gridControl = Chili.Grid:New{
name = 'foogrid',
width = 200,
height = 200,
children = {
Chili.Button:New{backgroundColor = {0,0.6,0,1}, textColor = {1,1,1,1}, caption = "Toggle", OnMouseUp = {ToggleOrientation}},
Chili.Button:New{caption = "2"},
Chili.Button:New{caption = "3"},
Chili.Button:New{caption = "4", margin = {10, 10, 10, 10}},
Chili.Button:New{caption = "5"},
Chili.Button:New{caption = "6"},
Chili.Button:New{caption = "7"},
}
}
gridWindow0 = Chili.Window:New{
parent = Chili.Screen0,
x = 450,
y = 450,
clientWidth = 200,
clientHeight = 200,
children = {
gridControl
},
}
gridWindow1 = Chili.Window:New{
parent = Chili.Screen0,
x = 650,
y = 750,
clientWidth = 200,
clientHeight = 200,
children = {
Chili.Button:New{right=0, bottom=0, caption = "2", OnClick={function()
--gridWindow1:GetObjectByName("tree_inspector")
end}},
Chili.TextBox:New{x=0, right=0, y=0, text = testText2},
Chili.EditBox:New{width = 200, y = 40, --[[autosize = true,]] text = testText3},
Chili.ComboBox:New{right = 10, x = 0, y = 90, items = { "opt1", "opt2", "opt3", "opt4", "opt5", "opt6", "opt7", "opt8", "opt9", "opt10", "opt11", "opt12", }},
Chili.Button:New{
caption = "Dispose Me",
name = "btn_dispose_me2",
x="5%", y=70,
width = "90%",
OnClick = {function(self) self:Dispose() end},
},
Chili.Button:New{
caption = "Dispose Me",
name = "btn_dispose_me3",
x="5%", y=90,
width = "90%",
},
Chili.Button:New{
caption = "Dispose Me",
name = "btn_dispose_me4",
x=0, y=120,
},
},
}
gridWindow1:GetObjectByName("btn_dispose_me4"):Dispose()
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
windowImageList = Chili.Window:New{
x = 700,
y = 200,
clientWidth = 410,
clientHeight = 400,
parent = Chili.Screen0,
}
local control = Chili.ScrollPanel:New{
x=0, right=0,
y=0, bottom=0,
parent = windowImageList,
children = {
--Button:New{width = 410, height = 400, anchors = {top=true,left=true,bottom=true,right=true}},
Chili.ImageListView:New{
name = "MyImageListView",
x=0, right=0,
y=0, bottom=0,
dir = "LuaUI/Images/",
OnSelectItem = {
function(obj,itemIdx,selected)
Spring.Echo("image selected ",itemIdx,selected)
end,
},
OnDblClickItem = {
function(obj,itemIdx)
Spring.Echo("image dblclicked ",itemIdx)
end,
},
OnDirChange = {
function(obj,itemIdx)
if obj.parent and obj.parent:InheritsFrom("scrollpanel") then
obj.parent:SetScrollPos(0,0)
end
end,
}
}
}
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
window1 = Chili.Window:New{
x = 450,
y = 200,
clientWidth = 200,
clientHeight = 200,
resizable = true,
draggable = true,
parent = Chili.Screen0,
children = {
Chili.ScrollPanel:New{
width = 200,
height = 200,
x=0, right=0,
y=0, bottom=0,
horizontalScrollbar = false,
children = {
Chili.TextBox:New{width = 200, x=0, right=0, y=0, bottom=0, text = testText}
},
},
}
}
window2 = Chili.Window:New{
x = 900,
y = 650,
width = 200,
height = 200,
parent = Chili.Screen0,
children = {
Chili.TabBar:New{
x=0, right=0,
y=0, height=20,
minItemWidth = 50,
tabs = {"tab1", "tab2", "tab3",},
},
Chili.ScrollPanel:New{
x=0, right=0,
y=30, bottom=0,
children = {
Chili.TreeView:New{
x=0, right=0,
y=0, bottom=0,
defaultExpanded = true,
nodes = {
"foo",
{ "bar" },
"do",
{ "re", {"mi"} },
"la",
{ "le", "lu" },
},
},
},
},
},
}
local warnDispose = function(self)
local ref = 0
for i,v in pairs(self._hlinks) do
ref = ref + 1
end
Spring.Echo("Warning object disposed!", self.classname, self.name, ref)
end
window3 = Chili.Window:New{
caption = "autosize test",
x = 1200,
y = 650,
width = 200,
height = 200,
parent = Chili.Screen0,
autosize = true,
savespace = true,
--debug = true,
children = {
Chili.Button:New{name = "btn_0", y = 20, width = 120, caption = "dispose btns below", OnClick = {function(self)
local btna = window3:GetObjectByName("btn_a");
local btnb = window3:GetObjectByName("btn_b");
window3:RemoveChild(btna);
window3:RemoveChild(btnb);
end}},
Chili.Button:New{name = "btn_a", y = 50, width = 120, caption = "autosize", OnDispose = {warnDispose}, OnClick = {function(self) window3:GetObjectByName("btn_a"):ToggleVisibility(); window3:GetObjectByName("btn_b"):ToggleVisibility(); end}},
Chili.Button:New{name = "btn_b", y = 80, width = 120, caption = "autosize", OnDispose = {warnDispose}, OnClick = {function(self) window3:GetObjectByName("btn_a"):ToggleVisibility(); window3:GetObjectByName("btn_b"):ToggleVisibility(); end}},
},
}
window3:GetObjectByName("btn_b"):Hide()
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
end --Initialize
function widget:Update()
local btn = gridWindow1:GetObjectByName("btn_dispose_me3")
btn:Dispose()
widgetHandler:RemoveCallIn("Update")
end
function widget:Shutdown()
window0:Dispose()
window01:Dispose()
gridWindow0:Dispose()
gridWindow1:Dispose()
windowImageList:Dispose()
window1:Dispose()
window2:Dispose()
window3:Dispose()
end