This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test3.nim
415 lines (349 loc) · 10.9 KB
/
test3.nim
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# --- Test 3. Work with Control nodes. --- #
# To change scene press SPACE.
import
nodesnim,
unittest
suite "Work with Control nodes.":
test "Setup window":
Window("Control test", 1280, 640)
test "Setup scenes":
build:
- Scene main
- Scene second_scene
addMainScene(main)
addScene(second_scene)
test "Register events":
addButtonAction("click", BUTTON_LEFT)
addKeyAction("space", K_SPACE)
addKeyAction("enter", 13)
test "Control test":
build:
- Control control
getSceneByName("main").addChild(control)
test "ColorRect test":
build:
- ColorRect rect:
color: Color(1, 0.8, 0.95, 0.8)
test "Handle Control events":
rect@onFocus(self):
echo "focused"
rect@onUnfocus(self):
echo "unfocused"
rect@onClick(self, x, y):
echo "clicked in (", x, ", ", y, ")"
rect@onRelease(self, x, y):
echo "released in (", x, ", ", y, ")"
rect.color.r = 1f
rect@onPress(self, x, y):
rect.color.r -= 0.01
rect@onMouseEnter(self, x, y):
rect.color.g = 0.5f
rect@onMouseExit(self, x, y):
rect.color.g = 0.8f
getSceneByName("main").addChild(rect)
test "Anchor settings test":
build:
- ColorRect rect1:
color: Color(0.2, 0.3, 0.4)
call move(40, 0)
call resize(80, 80)
- ColorRect rect2:
color: Color(0.4, 0.3, 0.2)
call setSizeAnchor(0.25, 0.5)
call setAnchor(1, 1, 1, 1) # anchor to bottom-right
getSceneByName("main").addChild(rect1)
test "Change scenes test": # Press Space to change scene
getSceneByName("main")@onProcess(self):
if isActionJustPressed("space"):
changeScene("second_scene")
getSceneByName("second_scene")@onProcess(self):
if isActionJustPressed("space"):
changeScene("main")
test "TextureRect test":
build:
- TextureRect texturerect1:
texture_mode: TEXTURE_KEEP_ASPECT_RATIO
texture_anchor: Anchor(0.5, 0.5, 0.5, 0.5)
call:
setTexture(load("assets/sharp.jpg"))
resize(100, 100)
move(120, 0)
- TextureRect texturerect2:
texture_mode: TEXTURE_CROP
texture_anchor: Anchor(0.5, 0.5, 0.5, 0.5)
call:
setTexture(load("assets/sharp.jpg"))
resize(100, 100)
move(220, 0)
- TextureRect texturerect3:
texture_mode: TEXTURE_FILL_XY
call:
setTexture(load("assets/sharp.jpg"))
resize(100, 100)
move(320, 0)
getSceneByName("main").addChildren(texturerect1, texturerect2, texturerect3)
test "Label test":
build:
- Label label:
call setText("hello,\nworld!\n VK!")
call move(0, 40)
label.text.setColor(6, 12, Color("#664fff"))
label.text.setURL(18, 19, "https://vk.com")
label.text.setUnderline(0, 2, true)
label.text.setStrikethrough(1, 3, true)
label.text.setItalic(0, true)
getSceneByName("main").addChild(label)
test "Button test":
build:
- Button btn:
call:
setText("Press me ^^")
resize(196, 32)
move(420, 0)
btn@onTouch(self, x, y):
echo "clicked btn!"
echo btn.text.chars[0].color
if current_theme.name == "default":
changeTheme("light")
else:
changeTheme("default")
getSceneByName("main").addChild(btn)
test "Box test":
build:
- Box box:
call:
setChildAnchor(0.5, 0.5, 0.5, 0.5)
setPadding(2, 4, 8, 16)
move(420, 30)
setBackgroundColor(Color(1f, 1f, 1f))
- ColorRect first:
color: Color(0xff6699ff'u32)
call resize(80, 80)
- ColorRect second:
color: Color(0xff64ffff'u32)
call resize(60, 60)
- ColorRect third:
color: Color(0xffaa00ff'u32)
getSceneByName("main").addChild(box)
test "HBox test":
build:
- HBox hbox:
call:
setChildAnchor(1, 1, 1, 1)
setPadding(2, 4, 8, 16)
move(520, 30)
setBackgroundColor(Color(1f, 1f, 1f))
- ColorRect first:
color: Color(0xff6699ff'u32)
call resize(80, 80)
- ColorRect second:
color: Color(0xff64ffff'u32)
call resize(60, 60)
- ColorRect third:
color: Color(0xffaa00ff'u32)
getSceneByName("main").addChild(hbox)
test "VBox test":
build:
- VBox vbox:
call:
setChildAnchor(1, 1, 1, 1)
setPadding(2, 4, 8, 16)
move(420, 144)
setBackgroundColor(Color(1f, 1f, 1f))
- ColorRect first:
color: Color(0xff6699ff'u32)
call resize(80, 80)
- ColorRect second:
color: Color(0xff64ffff'u32)
call resize(60, 60)
- ColorRect third:
color: Color(0xffaa00ff'u32)
getSceneByName("main").addChild(vbox)
test "GridBox test":
build:
- GridBox grid:
call:
setPadding(2, 4, 8, 16)
move(530, 144)
setRow(3)
setBackgroundColor(Color(1f, 1f, 1f))
- ColorRect first(color: Color(0xff6699ff'u32))
- ColorRect second(color: Color(0xff64ffff'u32))
- ColorRect third(color: Color(0xffaa00ff'u32))
- ColorRect fourth(color: Color(0xffcc33ff'u32))
- ColorRect fifth(color: Color(0xffcc66ff'u32))
- ColorRect sixth(color: Color(0xff6655ff'u32))
getSceneByName("main").addChild(grid)
test "EditText test":
build:
- EditText edit:
call move(0, 150)
getSceneByName("main").addChild(edit)
test "Scroll test":
# TODO: Fix it with glFramebuffer
build:
- Scroll scroll:
call setAnchor(1, 0, 1, 0)
- GridBox grid:
call:
setPadding(2, 4, 8, 16)
setBackgroundColor(Color(1f, 1f, 1f))
setRow(3)
- ColorRect first(color: Color(0xff6699ff'u32), rect_size: Vector2(100, 200))
- ColorRect second(color: Color(0xff64ffff'u32))
- ColorRect third(color: Color(0xffaa00ff'u32))
- ColorRect fourth(color: Color(0xffcc33ff'u32))
- ColorRect fifth(color: Color(0xffcc66ff'u32))
- ColorRect sixth(color: Color(0xff6655ff'u32))
getSceneByName("main").addChild(scroll)
test "ProgressBar test":
build:
- ProgressBar bar1:
progress_type: PROGRESS_BAR_HORIZONTAL
indeterminate: true
call:
setProgress(50)
move(120, 110)
resize(100, 20)
- ProgressBar bar2:
progress_type: PROGRESS_BAR_VERTICAL
indeterminate: true
call:
setProgress(50)
move(220, 100)
resize(20, 110)
- ProgressBar bar3:
progress_type: PROGRESS_BAR_CIRCLE
indeterminate: true
call:
setProgress(50)
move(320, 110)
resize(100, 100)
getSceneByName("main").addChildren(bar1, bar2, bar3)
test "Popup test":
build:
- Popup popup:
call setAnchor(0, 1, 0, 1)
- Label text:
call setText("popup!")
getSceneByName("main").getNode("control")@onProcess(self):
if isActionJustPressed("enter"):
popup.toggle()
getSceneByName("main").addChild(popup)
test "TextureButton test":
build:
- TextureButton button:
call:
setNormalTexture(load("assets/button_normal.png", GL_RGBA))
setHoverTexture(load("assets/button_hover.png", GL_RGBA))
setPressTexture(load("assets/button_press.png", GL_RGBA))
resize(256, 64)
move(120, 220)
setText("Texture button")
getSceneByName("main").addChild(button)
test "TextureProgressBar test":
build:
- TextureProgressBar progress:
call:
setProgressTexture(load("assets/texture_progress_1.png", GL_RGBA))
setBackgroundTexture(load("assets/texture_progress_0.png", GL_RGBA))
setProgress(50)
resize(256, 85)
move(100, 300)
getSceneByName("main").addChild(progress)
test "Counter test":
build:
- Counter counter:
call move(360, 360)
call setMaxValue(100)
getSceneByName("main").addChild(counter)
test "Switch test":
build:
- Switch switch:
call move(360, 400)
getSceneByName("main").addChild(switch)
test "CheckBox test":
build:
- CheckBox check:
call:
setText("smth checkbox")
enable()
move(700, 300)
getSceneByName("main").addChild(check)
test "SubWindow test":
build:
- SubWindow window1:
call:
setIcon("assets/anim/0.jpg")
setTitle("subwindow")
move(500, 400)
open()
getSceneByName("main").addChild(window1)
test "Slider test":
build:
- Slider slider1:
slider_type: SLIDER_HORIZONTAL
call resize(100, 10)
call move(600, 300)
- Slider slider2:
slider_type: SLIDER_VERTICAL
call resize(10, 100)
call move(600, 310)
getSceneByName("main").addChildren(slider1, slider2)
test "ToolTip test":
build:
- ToolTip tooltip:
call showAtMouse()
@onProcess():
tooltip.showAtMouse()
getSceneByName("main").addChild(tooltip)
test "Line & Bar chart test":
build:
- Chart my_chart:
call:
addChartData(
newChartData(
@["one", "two", "three", "four", "five", "six"],
@[1, 8, 18, 32, 4, 16], "myData", current_theme~accent_dark, BAR_CHART))
addChartData(
newChartData(
@["one", "two", "three", "four", "five", "six"],
@[1, 8, 18, 32, 4, 16], "myData", current_theme~accent, LINE_CHART))
move(100, 450)
resize(320, 196)
getSceneByName("main").addChildren(my_chart)
test "Pie chart test":
build:
- Chart circle_chart:
call:
addChartData(
newChartData(
@["one", "two", "three", "four", "five", "six"],
@[1, 8, 18, 32, 4, 16], "myData", current_theme~accent_dark, PIE_CHART))
move(900, 450)
resize(128, 128)
getSceneByName("main").addChildren(circle_chart)
test "Radar chart test":
build:
- Chart spiderweb_chart:
call:
addChartData(
newChartData(
@["one", "two", "three", "four", "five"],
@[10, 24, 18, 32, 4], "myData", current_theme~accent_dark, RADAR_CHART))
move(700, 450)
resize(196, 196)
getSceneByName("main").addChildren(spiderweb_chart)
test "Treeview test":
build:
- TreeView tree:
call:
bindTree(getSceneByName("main").toTree())
- TreeView directory_tree:
call:
bindTree(dirToTree("assets"))
move(250, 0)
echo tree.tree
getSceneByName("second_scene").addChildren(tree, directory_tree)
test "Launch window":
runApp()