-
Notifications
You must be signed in to change notification settings - Fork 31
/
demo.nim
404 lines (377 loc) · 10.3 KB
/
demo.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
## A bunch of nice looking controls.
import fidget
loadFont("IBM Plex Sans", "IBMPlexSans-Regular.ttf")
loadFont("IBM Plex Sans Bold", "IBMPlexSans-Bold.ttf")
var
textInputVar = ""
checkBoxValue: bool
radioBoxValue: bool
selectedTab = "Controls"
selectedButton = @["This"]
pipDrag = false
pipPos = 89
progress = 20.0
dropDownOpen = false
proc basicText() =
frame "autoLayoutText":
box 130, 0, root.box.w - 130, 491
fill "#ffffff"
layout lmVertical
counterAxisSizingMode csFixed
horizontalPadding 30
verticalPadding 30
itemSpacing 10
text "p2":
box 30, 361, 326, 100
fill "#000000"
font "IBM Plex Sans", 14, 400, 20, hLeft, vTop
characters "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
textAutoResize tsHeight
layoutAlign laStretch
text "title2":
box 30, 319, 326, 32
fill "#000000"
font "IBM Plex Sans", 20, 400, 32, hLeft, vTop
characters "Lorem Ipsum"
textAutoResize tsHeight
layoutAlign laStretch
text "imgCaption":
box 30, 289, 326, 20
fill "#9c9c9c"
font "IBM Plex Sans", 14, 400, 20, hCenter, vTop
characters "Lorem ipsum dolor sit ame"
textAutoResize tsHeight
layoutAlign laStretch
rectangle "imgPlaceholder":
box 125.5, 182, 135, 97
fill "#5C8F9C"
layoutAlign laCenter
text "p1":
box 30, 72, 326, 100
fill "#000000"
font "IBM Plex Sans", 14, 400, 20, hLeft, vTop
characters "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
textAutoResize tsHeight
layoutAlign laStretch
text "title1":
box 30, 30, 326, 32
fill "#000000"
font "IBM Plex Sans", 20, 400, 32, hLeft, vTop
characters "Lorem Ipsum"
textAutoResize tsHeight
layoutAlign laStretch
proc basicControls() =
group "dropdown":
box 260, 115, 100, 20
fill "#72bdd0"
cornerRadius 5
strokeWeight 1
onHover:
fill "#5C8F9C"
onClick:
dropDownOpen = not dropDownOpen
instance "arrow":
box 80, 0, 20, 20
if dropDownOpen:
rotation -90
image "arrow.png"
text "text":
box 0, 0, 80, 20
fill "#ffffff"
strokeWeight 1
font "IBM Plex Sans", 12, 200, 0, hCenter, vCenter
characters "Dropdown"
if dropDownOpen:
frame "dropDown":
box 0, 30, 100, 100
fill "#ffffff"
cornerRadius 5
layout lmVertical
counterAxisSizingMode csAuto
horizontalPadding 0
verticalPadding 0
itemSpacing 0
clipContent true
for buttonName in reverse(@["Nim", "UI", "in", "100%", "Nim"]):
group "button":
box 0, 80, 100, 20
layoutAlign laCenter
fill "#72bdd0"
onHover:
fill "#5C8F9C"
onClick:
dropDownOpen = false
text "text":
box 0, 0, 100, 20
fill "#ffffff"
font "IBM Plex Sans", 12, 400, 0, hCenter, vCenter
characters buttonName
group "progress":
box 260, 149, 250, 12
fill "#ffffff"
stroke "#70bdcf"
cornerRadius 5
strokeWeight 1
rectangle "fill":
progress = selectedButton.len / 5 * 100
box 2, 2, int((parent.box.w - 4) * (progress/100)), 8
fill "#9fe7f8"
cornerRadius 5
group "checkbox":
box 152, 85, 91, 20
onClick:
checkBoxValue = not checkBoxValue
rectangle "square":
box 0, 2, 16, 16
if checkBoxValue:
fill "#9FE7F8"
else:
fill "#ffffff"
stroke "#70bdcf"
cornerRadius 5
strokeWeight 1
text "text":
box 21, 0, 70, 20
fill "#46607e"
strokeWeight 1
font "IBM Plex Sans", 12, 200, 0, hLeft, vCenter
characters "Checkbox"
group "radiobox":
box 152, 115, 91, 20
onClick:
radioBoxValue = not radioBoxValue
rectangle "circle":
box 0, 2, 16, 16
if radioBoxValue:
fill "#9FE7F8"
else:
fill "#ffffff"
stroke "#72bdd0"
cornerRadius 8
strokeWeight 1
text "text":
box 21, 0, 70, 20
fill "#46607e"
strokeWeight 1
font "IBM Plex Sans", 12, 200, 0, hLeft, vCenter
characters "Radiobox"
group "slider":
box 260, 90, 250, 10
onClick:
pipDrag = true
if pipDrag:
pipPos = int(mouse.pos.x - current.screenBox.x)
pipPos = clamp(pipPos, 0, 240)
pipDrag = buttonDown[MOUSE_LEFT]
rectangle "pip":
box pipPos, 0, 10, 10
fill "#72bdd0"
cornerRadius 5
rectangle "fill":
box 0, 3, pipPos, 4
fill "#70bdcf"
cornerRadius 2
strokeWeight 1
rectangle "bg":
box 0, 3, 250, 4
fill "#c2e3eb"
cornerRadius 2
strokeWeight 1
frame "segmentedControl":
box 260, 55, 250, 20
fill "#72bdd0"
cornerRadius 5
layout lmHorizontal
counterAxisSizingMode csAuto
horizontalPadding 0
verticalPadding 0
itemSpacing 0
for buttonName in reverse(@["This", "is", "a", "segmented", "button"]):
group "Button":
box 0, 0, buttonName.len * 9 + 10, 20
layoutAlign laCenter
if buttonName in selectedButton:
fill "#ffffff", 0.5
onHover:
fill "#5C8F9C"
onClick:
if buttonName in selectedButton:
selectedButton.del(selectedButton.find(buttonName))
else:
selectedButton.add(buttonName)
text "text":
box 0, 0, buttonName.len * 9 + 10, 20
fill "#ffffff"
font "IBM Plex Sans", 12, 400, 0, hCenter, vCenter
characters buttonName
rectangle "separator":
box 0, 0, 1, 20
fill "#ffffff", 0.5
group "button":
box 150, 55, 90, 20
cornerRadius 5
fill "#72bdd0"
onHover:
fill "#5C8F9C"
onDown:
fill "#3E656F"
text "text":
box 0, 0, 90, 20
fill "#ffffff"
font "IBM Plex Sans", 12, 200, 0, hCenter, vCenter
characters "Button"
group "input":
box 260, 15, 250, 30
text "text":
box 9, 8, 232, 15
fill "#46607e"
strokeWeight 1
font "IBM Plex Sans", 12, 200, 0, hLeft, vCenter
binding textInputVar
text "textPlaceholder":
box 9, 8, 232, 15
fill "#46607e", 0.5
strokeWeight 1
font "IBM Plex Sans", 12, 200, 0, hLeft, vCenter
if textInputVar == "":
characters "Start typing here"
rectangle "bg":
box 0, 0, 250, 30
stroke "#72bdd0"
cornerRadius 5
strokeWeight 1
group "label":
box 150, 15, 100, 30
text "Text field:":
box 0, 0, 100, 30
fill "#46607e"
strokeWeight 1
font "IBM Plex Sans", 12, 200, 0, hLeft, vCenter
characters "Text field:"
proc basicImage() =
frame "images":
box 130, 0, 400, 400
fill "#ffffff"
group "img1":
box 260, 260, 100, 100
image "img1.png"
group "img2":
box 260, 150, 100, 100
image "img2.png"
group "img3":
box 260, 40, 100, 100
image "img3.png"
group "img4":
box 150, 260, 100, 100
image "img4.png"
group "img5":
box 150, 150, 100, 100
image "img5.png"
group "img6":
box 150, 40, 100, 100
image "img6.png"
group "img7":
box 40, 260, 100, 100
image "img7.png"
group "img8":
box 40, 150, 100, 100
image "img8.png"
group "img9":
box 40, 40, 100, 100
image "img9.png"
proc basicConstraints() =
frame "constraints":
# Got to specify orgBox for constraints to work.
orgBox 0, 0, 400, 400
# Then grow the normal box.
box 130, 0, root.box.w - 130, root.box.h
# Constraints will work on the difference between orgBox and box.
fill "#ffffff"
rectangle "Center":
box 150, 150, 100, 100
constraints cCenter, cCenter
fill "#FFFFFF", 0.50
rectangle "Scale":
box 100, 100, 200, 200
constraints cScale, cScale
fill "#FFFFFF", 0.25
rectangle "LRTB":
box 40, 40, 320, 320
constraints cStretch, cStretch
fill "#70BDCF"
rectangle "TR":
box 360, 20, 20, 20
constraints cMax, cMin
fill "#70BDCF"
rectangle "TL":
box 20, 20, 20, 20
constraints cMin, cMin
fill "#70BDCF"
rectangle "BR":
box 360, 360, 20, 20
constraints cMax, cMax
fill "#70BDCF"
rectangle "BL":
box 20, 360, 20, 20
constraints cMin, cMax
fill "#70BDCF"
proc drawMain() =
setTitle("Fidget Example")
component "iceUI":
orgBox 0, 0, 530, 185
box root.box
fill "#ffffff"
group "shadow":
orgBox 0, 0, 530, 3
box 0, 0, root.box.w, 3
rectangle "l1":
box 0, 0, 530, 1
constraints cStretch, cMin
fill "#000000", 0.10
rectangle "l2":
box 0, 1, 530, 1
constraints cStretch, cMin
fill "#000000", 0.07
rectangle "l3":
box 0, 2, 530, 1
constraints cStretch, cMin
fill "#000000", 0.03
frame "verticalTabs":
box 0, 15, 130, 120
layout lmVertical
counterAxisSizingMode csAuto
horizontalPadding 0
verticalPadding 0
itemSpacing 0
for tabName in ["Constraints", "Image", "Text", "Controls"]:
group "tab":
box 0, 0, 130, 30
layoutAlign laCenter
onHover:
fill "#70bdcf", 0.5
if selectedTab == tabName:
fill "#70bdcf"
onClick:
selectedTab = tabName
text "text":
box 25, 0, 105, 30
if selectedTab == tabName:
fill "#ffffff"
else:
fill "#46607e"
font "IBM Plex Sans", 12, 400, 12, hLeft, vCenter
characters tabName
rectangle "bg":
box 0, 0, 130, 185
constraints cMin, cStretch
fill "#e5f7fe"
case selectedTab:
of "Controls":
basicControls()
of "Text":
basicText()
of "Image":
basicImage()
of "Constraints":
basicConstraints()
startFidget(drawMain, w = 530, h = 300)