-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathmain.nim
More file actions
843 lines (756 loc) · 29.2 KB
/
main.nim
File metadata and controls
843 lines (756 loc) · 29.2 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
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
import std/[strutils, os, strformat]
import downit
import chroma
import imstyle
import niprefs
import tinydialogs
import nimgl/[opengl, glfw]
import nimgl/imgui, nimgl/imgui/[impl_opengl, impl_glfw]
import src/[prefsmodal, browseview, editview, utils, icons]
when defined(release):
from resourcesdata import resources
const
configPath = "config.toml"
sidebarViews = [
FA_PencilSquareO, # Edit view
FA_Search, # Browse view
]
let classicTheme = toToml {
name: "Classic",
author: "ocornut",
readonly: true,
style: {
"alpha": 1.0,
"disabledalpha": 0.6000000238418579,
"windowPadding": @[8.0, 8.0],
"windowRounding": 0.0,
"windowBorderSize": 1.0,
"windowMinSize": @[32.0, 32.0],
"windowTitleAlign": @[0.0, 0.5],
"windowmenubuttonposition": "Left",
"childRounding": 0.0,
"childBorderSize": 1.0,
"popupRounding": 0.0,
"popupBorderSize": 1.0,
"framePadding": @[4.0, 3.0],
"frameRounding": 0.0,
"frameBorderSize": 0.0,
"itemspacing": @[8.0, 4.0],
"iteminnerspacing": @[4.0, 4.0],
"cellPadding": @[4.0, 2.0],
"touchextraPadding": @[0.0, 0.0],
"indentspacing": 21.0,
"columnsminspacing": 6.0,
"scrollbarSize": 14.0,
"scrollbarRounding": 9.0,
"grabMinSize": 10.0,
"grabRounding": 0.0,
"logSliderDeadzone": 4.0,
"tabRounding": 4.0,
"tabBorderSize": 0.0,
"tabminwidthforclosebutton": 0.0,
"colorbuttonposition": "Right",
"buttonTextAlign": @[0.5, 0.5],
"selectableTextAlign": @[0.0, 0.0],
"displayWindowPadding": @[19.0, 19.0],
"displaySafeAreaPadding": @[3.0, 3.0],
"mouseCursorScale": 1.0,
"antiAliasedLines": true,
"antiAliasedLinesUseTex": true,
"antiAliasedFill": true,
"curveTessellationTol": 1.25,
"circleTessellationMaxError": 0.300000011920929,
"colors": {
"Text": "rgba(229, 229, 229, 1.0)",
"TextDisabled": "rgba(153, 153, 153, 1.0)",
"WindowBg": "rgba(0, 0, 0, 0.8500000238418579)",
"ChildBg": "rgba(0, 0, 0, 0.0)",
"PopupBg": "rgba(28, 28, 35, 0.9200000166893005)",
"Border": "rgba(127, 127, 127, 0.5)",
"BorderShadow": "rgba(0, 0, 0, 0.0)",
"FrameBg": "rgba(109, 109, 109, 0.3899999856948853)",
"FrameBgHovered": "rgba(119, 119, 175, 0.4000000059604645)",
"FrameBgActive": "rgba(107, 104, 163, 0.6899999976158142)",
"TitleBg": "rgba(68, 68, 137, 0.8299999833106995)",
"TitleBgActive": "rgba(81, 81, 160, 0.8700000047683716)",
"TitleBgCollapsed": "rgba(102, 102, 204, 0.2000000029802322)",
"MenuBarBg": "rgba(102, 102, 140, 0.800000011920929)",
"ScrollbarBg": "rgba(51, 63, 76, 0.6000000238418579)",
"ScrollbarGrab": "rgba(102, 102, 204, 0.300000011920929)",
"ScrollbarGrabHovered": "rgba(102, 102, 204, 0.4000000059604645)",
"ScrollbarGrabActive": "rgba(104, 99, 204, 0.6000000238418579)",
"Checkmark": "rgba(229, 229, 229, 0.5)",
"Slidergrab": "rgba(255, 255, 255, 0.300000011920929)",
"SlidergrabActive": "rgba(104, 99, 204, 0.6000000238418579)",
"Button": "rgba(89, 102, 155, 0.6200000047683716)",
"ButtonHovered": "rgba(102, 122, 181, 0.7900000214576721)",
"ButtonActive": "rgba(117, 137, 204, 1.0)",
"Header": "rgba(102, 102, 229, 0.449999988079071)",
"HeaderHovered": "rgba(114, 114, 229, 0.800000011920929)",
"HeaderActive": "rgba(135, 135, 221, 0.800000011920929)",
"Separator": "rgba(127, 127, 127, 0.6000000238418579)",
"SeparatorHovered": "rgba(153, 153, 178, 1.0)",
"SeparatorActive": "rgba(178, 178, 229, 1.0)",
"ResizeGrip": "rgba(255, 255, 255, 0.1000000014901161)",
"ResizeGripHovered": "rgba(198, 209, 255, 0.6000000238418579)",
"ResizeGripActive": "rgba(198, 209, 255, 0.8999999761581421)",
"Tab": "rgba(85, 85, 174, 0.7860000133514404)",
"TabHovered": "rgba(114, 114, 229, 0.800000011920929)",
"TabActive": "rgba(103, 103, 185, 0.8420000076293945)",
"TabUnfocused": "rgba(72, 72, 145, 0.8212000131607056)",
"TabUnfocusedActive": "rgba(89, 89, 166, 0.8371999859809875)",
"PlotLines": "rgba(255, 255, 255, 1.0)",
"PlotLinesHovered": "rgba(229, 178, 0, 1.0)",
"PlotHistogram": "rgba(229, 178, 0, 1.0)",
"PlotHistogramHovered": "rgba(255, 153, 0, 1.0)",
"TableHeaderBg": "rgba(68, 68, 96, 1.0)",
"TableBorderStrong": "rgba(79, 79, 114, 1.0)",
"TableBorderLight": "rgba(66, 66, 71, 1.0)",
"TableRowBg": "rgba(0, 0, 0, 0.0)",
"TableRowBgAlt": "rgba(255, 255, 255, 0.07000000029802322)",
"TextSelectedBg": "rgba(0, 0, 255, 0.3499999940395355)",
"DragDropTarget": "rgba(255, 255, 0, 0.8999999761581421)",
"NavHighlight": "rgba(114, 114, 229, 0.800000011920929)",
"NavWindowingHighlight": "rgba(255, 255, 255, 0.699999988079071)",
"NavWindowingDimBg": "rgba(204, 204, 204, 0.2000000029802322)",
"ModalWindowDimBg": "rgba(51, 51, 51, 0.3499999940395355)",
},
},
}
let darkTheme = toToml {
name: "Dark",
author: "dougbinks",
readonly: true,
style: {
"alpha": 1.0,
"disabledalpha": 0.6000000238418579,
"windowPadding": @[8.0, 8.0],
"windowRounding": 0.0,
"windowBorderSize": 1.0,
"windowMinSize": @[32.0, 32.0],
"windowTitleAlign": @[0.0, 0.5],
"windowmenubuttonposition": "Left",
"childRounding": 0.0,
"childBorderSize": 1.0,
"popupRounding": 0.0,
"popupBorderSize": 1.0,
"framePadding": @[4.0, 3.0],
"frameRounding": 0.0,
"frameBorderSize": 0.0,
"itemspacing": @[8.0, 4.0],
"iteminnerspacing": @[4.0, 4.0],
"cellPadding": @[4.0, 2.0],
"touchextraPadding": @[0.0, 0.0],
"indentspacing": 21.0,
"columnsminspacing": 6.0,
"scrollbarSize": 14.0,
"scrollbarRounding": 9.0,
"grabMinSize": 10.0,
"grabRounding": 0.0,
"logSliderDeadzone": 4.0,
"tabRounding": 4.0,
"tabBorderSize": 0.0,
"tabminwidthforclosebutton": 0.0,
"colorbuttonposition": "Right",
"buttonTextAlign": @[0.5, 0.5],
"selectableTextAlign": @[0.0, 0.0],
"displayWindowPadding": @[19.0, 19.0],
"displaySafeAreaPadding": @[3.0, 3.0],
"mouseCursorScale": 1.0,
"antiAliasedLines": true,
"antiAliasedLinesUseTex": true,
"antiAliasedFill": true,
"curveTessellationTol": 1.25,
"circleTessellationMaxError": 0.300000011920929,
"colors": {
"Text": "rgba(255, 255, 255, 1.0)",
"TextDisabled": "rgba(127, 127, 127, 1.0)",
"WindowBg": "rgba(15, 15, 15, 0.9399999976158142)",
"ChildBg": "rgba(0, 0, 0, 0.0)",
"PopupBg": "rgba(20, 20, 20, 0.9399999976158142)",
"Border": "rgba(109, 109, 127, 0.5)",
"BorderShadow": "rgba(0, 0, 0, 0.0)",
"FrameBg": "rgba(40, 73, 122, 0.5400000214576721)",
"FrameBgHovered": "rgba(66, 150, 249, 0.4000000059604645)",
"FrameBgActive": "rgba(66, 150, 249, 0.6700000166893005)",
"TitleBg": "rgba(10, 10, 10, 1.0)",
"TitleBgActive": "rgba(40, 73, 122, 1.0)",
"TitleBgCollapsed": "rgba(0, 0, 0, 0.5099999904632568)",
"MenuBarBg": "rgba(35, 35, 35, 1.0)",
"ScrollbarBg": "rgba(5, 5, 5, 0.5299999713897705)",
"ScrollbarGrab": "rgba(79, 79, 79, 1.0)",
"ScrollbarGrabHovered": "rgba(104, 104, 104, 1.0)",
"ScrollbarGrabActive": "rgba(130, 130, 130, 1.0)",
"Checkmark": "rgba(66, 150, 249, 1.0)",
"Slidergrab": "rgba(61, 132, 224, 1.0)",
"SlidergrabActive": "rgba(66, 150, 249, 1.0)",
"Button": "rgba(66, 150, 249, 0.4000000059604645)",
"ButtonHovered": "rgba(66, 150, 249, 1.0)",
"ButtonActive": "rgba(15, 135, 249, 1.0)",
"Header": "rgba(66, 150, 249, 0.3100000023841858)",
"HeaderHovered": "rgba(66, 150, 249, 0.800000011920929)",
"HeaderActive": "rgba(66, 150, 249, 1.0)",
"Separator": "rgba(109, 109, 127, 0.5)",
"SeparatorHovered": "rgba(25, 102, 191, 0.7799999713897705)",
"SeparatorActive": "rgba(25, 102, 191, 1.0)",
"ResizeGrip": "rgba(66, 150, 249, 0.2000000029802322)",
"ResizeGripHovered": "rgba(66, 150, 249, 0.6700000166893005)",
"ResizeGripActive": "rgba(66, 150, 249, 0.949999988079071)",
"Tab": "rgba(45, 89, 147, 0.8619999885559082)",
"TabHovered": "rgba(66, 150, 249, 0.800000011920929)",
"TabActive": "rgba(50, 104, 173, 1.0)",
"TabUnfocused": "rgba(17, 26, 37, 0.9724000096321106)",
"TabUnfocusedActive": "rgba(34, 66, 108, 1.0)",
"PlotLines": "rgba(155, 155, 155, 1.0)",
"PlotLinesHovered": "rgba(255, 109, 89, 1.0)",
"PlotHistogram": "rgba(229, 178, 0, 1.0)",
"PlotHistogramHovered": "rgba(255, 153, 0, 1.0)",
"TableHeaderBg": "rgba(48, 48, 51, 1.0)",
"TableBorderStrong": "rgba(79, 79, 89, 1.0)",
"TableBorderLight": "rgba(58, 58, 63, 1.0)",
"TableRowBg": "rgba(0, 0, 0, 0.0)",
"TableRowBgAlt": "rgba(255, 255, 255, 0.05999999865889549)",
"TextSelectedBg": "rgba(66, 150, 249, 0.3499999940395355)",
"DragDropTarget": "rgba(255, 255, 0, 0.8999999761581421)",
"NavHighlight": "rgba(66, 150, 249, 1.0)",
"NavWindowingHighlight": "rgba(255, 255, 255, 0.699999988079071)",
"NavWindowingDimBg": "rgba(204, 204, 204, 0.2000000029802322)",
"ModalWindowDimBg": "rgba(204, 204, 204, 0.3499999940395355)",
},
},
}
let lightTheme = toToml {
name: "Light",
author: "dougbinks",
readonly: true,
style: {
"alpha": 1.0,
"disabledalpha": 0.6000000238418579,
"windowPadding": @[8.0, 8.0],
"windowRounding": 0.0,
"windowBorderSize": 1.0,
"windowMinSize": @[32.0, 32.0],
"windowTitleAlign": @[0.0, 0.5],
"windowmenubuttonposition": "Left",
"childRounding": 0.0,
"childBorderSize": 1.0,
"popupRounding": 0.0,
"popupBorderSize": 1.0,
"framePadding": @[4.0, 3.0],
"frameRounding": 0.0,
"frameBorderSize": 0.0,
"itemspacing": @[8.0, 4.0],
"iteminnerspacing": @[4.0, 4.0],
"cellPadding": @[4.0, 2.0],
"touchextraPadding": @[0.0, 0.0],
"indentspacing": 21.0,
"columnsminspacing": 6.0,
"scrollbarSize": 14.0,
"scrollbarRounding": 9.0,
"grabMinSize": 10.0,
"grabRounding": 0.0,
"logSliderDeadzone": 4.0,
"tabRounding": 4.0,
"tabBorderSize": 0.0,
"tabminwidthforclosebutton": 0.0,
"colorbuttonposition": "Right",
"buttonTextAlign": @[0.5, 0.5],
"selectableTextAlign": @[0.0, 0.0],
"displayWindowPadding": @[19.0, 19.0],
"displaySafeAreaPadding": @[3.0, 3.0],
"mouseCursorScale": 1.0,
"antiAliasedLines": true,
"antiAliasedLinesUseTex": true,
"antiAliasedFill": true,
"curveTessellationTol": 1.25,
"circleTessellationMaxError": 0.300000011920929,
"colors": {
"Text": "rgba(0, 0, 0, 1.0)",
"TextDisabled": "rgba(153, 153, 153, 1.0)",
"WindowBg": "rgba(239, 239, 239, 1.0)",
"ChildBg": "rgba(0, 0, 0, 0.0)",
"PopupBg": "rgba(255, 255, 255, 0.9800000190734863)",
"Border": "rgba(0, 0, 0, 0.300000011920929)",
"BorderShadow": "rgba(0, 0, 0, 0.0)",
"FrameBg": "rgba(255, 255, 255, 1.0)",
"FrameBgHovered": "rgba(66, 150, 249, 0.4000000059604645)",
"FrameBgActive": "rgba(66, 150, 249, 0.6700000166893005)",
"TitleBg": "rgba(244, 244, 244, 1.0)",
"TitleBgActive": "rgba(209, 209, 209, 1.0)",
"TitleBgCollapsed": "rgba(255, 255, 255, 0.5099999904632568)",
"MenuBarBg": "rgba(219, 219, 219, 1.0)",
"ScrollbarBg": "rgba(249, 249, 249, 0.5299999713897705)",
"ScrollbarGrab": "rgba(175, 175, 175, 0.800000011920929)",
"ScrollbarGrabHovered": "rgba(124, 124, 124, 0.800000011920929)",
"ScrollbarGrabActive": "rgba(124, 124, 124, 1.0)",
"Checkmark": "rgba(66, 150, 249, 1.0)",
"Slidergrab": "rgba(66, 150, 249, 0.7799999713897705)",
"SlidergrabActive": "rgba(117, 137, 204, 0.6000000238418579)",
"Button": "rgba(66, 150, 249, 0.4000000059604645)",
"ButtonHovered": "rgba(66, 150, 249, 1.0)",
"ButtonActive": "rgba(15, 135, 249, 1.0)",
"Header": "rgba(66, 150, 249, 0.3100000023841858)",
"HeaderHovered": "rgba(66, 150, 249, 0.800000011920929)",
"HeaderActive": "rgba(66, 150, 249, 1.0)",
"Separator": "rgba(99, 99, 99, 0.6200000047683716)",
"SeparatorHovered": "rgba(35, 112, 204, 0.7799999713897705)",
"SeparatorActive": "rgba(35, 112, 204, 1.0)",
"ResizeGrip": "rgba(89, 89, 89, 0.1700000017881393)",
"ResizeGripHovered": "rgba(66, 150, 249, 0.6700000166893005)",
"ResizeGripActive": "rgba(66, 150, 249, 0.949999988079071)",
"Tab": "rgba(194, 203, 213, 0.9309999942779541)",
"TabHovered": "rgba(66, 150, 249, 0.800000011920929)",
"TabActive": "rgba(151, 185, 225, 1.0)",
"TabUnfocused": "rgba(234, 236, 238, 0.9861999750137329)",
"TabUnfocusedActive": "rgba(189, 209, 233, 1.0)",
"PlotLines": "rgba(99, 99, 99, 1.0)",
"PlotLinesHovered": "rgba(255, 109, 89, 1.0)",
"PlotHistogram": "rgba(229, 178, 0, 1.0)",
"PlotHistogramHovered": "rgba(255, 114, 0, 1.0)",
"TableHeaderBg": "rgba(198, 221, 249, 1.0)",
"TableBorderStrong": "rgba(145, 145, 163, 1.0)",
"TableBorderLight": "rgba(173, 173, 188, 1.0)",
"TableRowBg": "rgba(0, 0, 0, 0.0)",
"TableRowBgAlt": "rgba(76, 76, 76, 0.09000000357627869)",
"TextSelectedBg": "rgba(66, 150, 249, 0.3499999940395355)",
"DragDropTarget": "rgba(66, 150, 249, 0.949999988079071)",
"NavHighlight": "rgba(66, 150, 249, 0.800000011920929)",
"NavWindowingHighlight": "rgba(178, 178, 178, 0.699999988079071)",
"NavWindowingDimBg": "rgba(51, 51, 51, 0.2000000029802322)",
"ModalWindowDimBg": "rgba(51, 51, 51, 0.3499999940395355)",
},
},
}
let cherryTheme = toToml {
name: "Cherry",
author: "r-lyeh",
readonly: true,
style: {
"alpha": 1.0,
"disabledAlpha": 0.6000000238418579,
"windowPadding": @[6.0, 3.0],
"windowRounding": 0.0,
"windowBorderSize": 1.0,
"windowMinSize": @[32.0, 32.0],
"windowTitleAlign": @[0.5, 0.5],
"windowmenubuttonposition": "Left",
"childRounding": 0.0,
"childBorderSize": 1.0,
"popupRounding": 0.0,
"popupBorderSize": 1.0,
"framePadding": @[5.0, 1.0],
"frameRounding": 3.0,
"frameBorderSize": 1.0,
"itemspacing": @[7.0, 1.0],
"iteminnerspacing": @[1.0, 1.0],
"cellPadding": @[4.0, 2.0],
"touchextraPadding": @[0.0, 0.0],
"indentspacing": 6.0,
"columnsminspacing": 6.0,
"scrollbarSize": 13.0,
"scrollbarRounding": 16.0,
"grabMinSize": 20.0,
"grabRounding": 2.0,
"logSliderDeadzone": 4.0,
"tabRounding": 4.0,
"tabBorderSize": 1.0,
"tabminwidthforclosebutton": 0.0,
"colorbuttonposition": "Right",
"buttonTextAlign": @[0.5, 0.5],
"selectableTextAlign": @[0.0, 0.0],
"displayWindowPadding": @[19.0, 19.0],
"displaySafeAreaPadding": @[3.0, 0.0],
"mouseCursorScale": 1.0,
"antiAliasedLines": true,
"antiAliasedLinesUseTex": true,
"antiAliasedFill": true,
"curveTessellationTol": 1.25,
"circleTessellationMaxError": 0.300000011920929,
"colors": {
"Text": "rgba(219, 237, 226, 0.8799999952316284)",
"TextDisabled": "rgba(219, 237, 226, 0.2800000011920929)",
"WindowBg": "rgba(33, 35, 43, 1.0)",
"ChildBg": "rgba(0, 0, 0, 0.0)",
"PopupBg": "rgba(51, 56, 68, 0.8999999761581421)",
"Border": "rgba(137, 122, 65, 0.1620000004768372)",
"BorderShadow": "rgba(0, 0, 0, 0.0)",
"FrameBg": "rgba(51, 56, 68, 1.0)",
"FrameBgHovered": "rgba(116, 50, 76, 0.7799999713897705)",
"FrameBgActive": "rgba(116, 50, 76, 1.0)",
"TitleBg": "rgba(59, 51, 69, 1.0)",
"TitleBgActive": "rgba(128, 19, 65, 1.0)",
"TitleBgCollapsed": "rgba(51, 56, 68, 0.75)",
"MenuBarBg": "rgba(51, 56, 68, 0.4699999988079071)",
"ScrollbarBg": "rgba(51, 56, 68, 1.0)",
"ScrollbarGrab": "rgba(22, 38, 40, 1.0)",
"ScrollbarGrabHovered": "rgba(116, 50, 76, 0.7799999713897705)",
"ScrollbarGrabActive": "rgba(116, 50, 76, 1.0)",
"Checkmark": "rgba(181, 56, 68, 1.0)",
"Slidergrab": "rgba(119, 196, 211, 0.1400000005960464)",
"SlidergrabActive": "rgba(181, 56, 68, 1.0)",
"Button": "rgba(119, 196, 211, 0.1400000005960464)",
"ButtonHovered": "rgba(116, 50, 76, 0.8600000143051147)",
"ButtonActive": "rgba(116, 50, 76, 1.0)",
"Header": "rgba(116, 50, 76, 0.7599999904632568)",
"HeaderHovered": "rgba(116, 50, 76, 0.8600000143051147)",
"HeaderActive": "rgba(128, 19, 65, 1.0)",
"Separator": "rgba(109, 109, 127, 0.5)",
"SeparatorHovered": "rgba(25, 102, 191, 0.7799999713897705)",
"SeparatorActive": "rgba(25, 102, 191, 1.0)",
"ResizeGrip": "rgba(119, 196, 211, 0.03999999910593033)",
"ResizeGripHovered": "rgba(116, 50, 76, 0.7799999713897705)",
"ResizeGripActive": "rgba(116, 50, 76, 1.0)",
"Tab": "rgba(45, 89, 147, 0.8619999885559082)",
"TabHovered": "rgba(66, 150, 249, 0.800000011920929)",
"TabActive": "rgba(50, 104, 173, 1.0)",
"TabUnfocused": "rgba(17, 26, 37, 0.9724000096321106)",
"TabUnfocusedActive": "rgba(34, 66, 108, 1.0)",
"PlotLines": "rgba(219, 237, 226, 0.6299999952316284)",
"PlotLinesHovered": "rgba(116, 50, 76, 1.0)",
"PlotHistogram": "rgba(219, 237, 226, 0.6299999952316284)",
"PlotHistogramHovered": "rgba(116, 50, 76, 1.0)",
"TableHeaderBg": "rgba(48, 48, 51, 1.0)",
"TableBorderStrong": "rgba(79, 79, 89, 1.0)",
"TableBorderLight": "rgba(58, 58, 63, 1.0)",
"TableRowBg": "rgba(0, 0, 0, 0.0)",
"TableRowBgAlt": "rgba(255, 255, 255, 0.05999999865889549)",
"TextSelectedBg": "rgba(116, 50, 76, 0.4300000071525574)",
"DragDropTarget": "rgba(255, 255, 0, 0.8999999761581421)",
"NavHighlight": "rgba(66, 150, 249, 1.0)",
"NavWindowingHighlight": "rgba(255, 255, 255, 0.699999988079071)",
"NavWindowingDimBg": "rgba(204, 204, 204, 0.2000000029802322)",
"ModalWindowDimBg": "rgba(204, 204, 204, 0.3499999940395355)",
},
},
}
proc getData(path: string): string =
when defined(release):
resources[path]
else:
readFile(path)
proc getData(node: TomlValueRef): string =
assert node.kind == TomlKind.String
node.getString().getData()
proc drawAboutModal(app: App) =
var center: ImVec2
getCenterNonUDT(center.addr, igGetMainViewport())
igSetNextWindowPos(center, Always, igVec2(0.5f, 0.5f))
let unusedOpen = true # Passing this parameter creates a close button
if igBeginPopupModal(
cstring "About " & app.config["name"].getString(),
unusedOpen.unsafeAddr,
flags = makeFlags(ImGuiWindowFlags.NoResize),
):
# Display icon image
var texture: GLuint
var image = app.config["iconPath"].getData().readImageFromMemory()
image.loadTextureFromData(texture)
igImage(cast[ptr ImTextureID](texture), igVec2(64, 64))
# Or igVec2(image.width.float32, image.height.float32)
if igIsItemHovered():
igSetTooltip(cstring app.config["website"].getString() & " " & FA_ExternalLink)
if igIsMouseClicked(ImGuiMouseButton.Left):
app.config["website"].getString().openURL()
igSameLine()
igPushTextWrapPos(250)
igTextWrapped(app.config["comment"].getString().cstring)
igPopTextWrapPos()
igSpacing()
# To make it not clickable
igPushItemFlag(ImGuiItemFlags.Disabled, true)
igSelectable("Credits", true, makeFlags(ImGuiSelectableFlags.DontClosePopups))
igPopItemFlag()
if igBeginChild("##credits", igVec2(0, 75)):
for author in app.config["authors"]:
let (name, url) = block:
let (name, url) = author.getString().removeInside('<', '>')
(name.strip(), url.strip())
if igSelectable(cstring name) and url.len > 0:
url.openURL()
if igIsItemHovered() and url.len > 0:
igSetTooltip(cstring url & " " & FA_ExternalLink)
igEndChild()
igSpacing()
igText(app.config["version"].getString().cstring)
igEndPopup()
proc drawMainMenuBar(app: var App) =
var openAbout, openPrefs = false
if igBeginMainMenuBar():
if igBeginMenu("File"):
# igMenuItem("Preferences " & FA_Cog, "Ctrl+P", openPrefs.addr)
if igMenuItem("Quit " & FA_Times, "Ctrl+Q"):
app.win.setWindowShouldClose(true)
igEndMenu()
if igBeginMenu("Edit"):
igMenuItem("Show framerate", nil, app.showFramerate.addr)
if igMenuItem(cstring "Refresh Feed " & FA_Refresh) and
not app.downloader.running("feed"):
app.downloader.downloadAgain("feed")
igEndMenu()
if igBeginMenu("About"):
if igMenuItem("Website " & FA_ExternalLink):
app.config["website"].getString().openURL()
igMenuItem(
cstring "About " & app.config["name"].getString(),
shortcut = nil,
p_selected = openAbout.addr,
)
igEndMenu()
igEndMainMenuBar()
# See https:#github.com/ocornut/imgui/issues/331#issuecomment-751372071
if openPrefs:
igOpenPopup("Preferences")
if openAbout:
igOpenPopup(cstring "About " & app.config["name"].getString())
# These modals will only get drawn when igOpenPopup(name) are called, respectly
app.drawAboutModal()
app.drawPrefsModal()
proc drawSidebar(app: var App) =
const sidebarWidth = 50
var anyHovered = false
igPushFont(app.sidebarIconFont)
igPushStyleColor(ImGuiCol.WindowBg, igGetColor(WindowBg).darken(0.02).igVec4())
igPushStyleColor(ImGuiCol.Text, "#9A9996".parseHtmlHex().igVec4())
igPushStyleVar(ImGuiStyleVar.WindowPadding, igVec2(0, 20))
igPushStyleVar(ImGuiStyleVar.ItemSpacing, igVec2(0, 7))
if igBeginViewportSideBar(
"##sidebar", igGetMainViewport(), ImGuiDir.Left, sidebarWidth, ImGuiWindowFlags.None
):
for e, view in sidebarViews:
if app.currentView == e:
igPushStyleColor(ImGuiCol.Text, "#FFFFFF".parseHtmlHex().igVec4())
if app.hoveredView == e:
igPushStyleColor(ImGuiCol.Text, igGetColor(Text).lighten(0.2).igVec4())
igCenterCursorX(igCalcTextSize(cstring view).x, avail = sidebarWidth)
igText(cstring view)
if app.currentView == e:
igPopStyleColor()
if app.hoveredView == e:
igPopStyleColor()
if app.currentView != e and igIsItemHovered():
anyHovered = true
app.hoveredView = e
if igIsItemClicked():
app.currentView = e
igEnd()
if not anyHovered:
app.hoveredView = -1
igPopStyleVar(2)
igPopStyleColor(2)
igPopFont()
proc drawMain(app: var App) = # Draw the main window
let viewport = igGetMainViewport()
app.drawMainMenuBar()
app.drawSidebar()
# Work area is the entire viewport minus main menu bar, task bars, etc.
igSetNextWindowPos(viewport.workPos)
igSetNextWindowSize(viewport.workSize)
if igBegin(
cstring app.config["name"].getString(),
flags = makeFlags(
ImGuiWindowFlags.NoResize, ImGuiWindowFlags.NoBringToFrontOnFocus, NoDecoration,
NoMove,
),
):
if app.showFramerate:
igText(
FA_Info & " Application average %.3f ms/frame (%.1f FPS)",
1000f / igGetIO().framerate,
igGetIO().framerate,
)
if app.currentView == 0:
app.drawEditView()
elif app.currentView == 1:
app.drawBrowseView()
else:
igText("hello")
igEnd()
# GLFW clipboard -> ImGui clipboard
if (
let clip = app.win.getClipboardString()
not clip.isNil and $clip != app.lastClipboard
):
igSetClipboardText(clip)
app.lastClipboard = $clip
# ImGui clipboard -> GLFW clipboard
if (let clip = igGetClipboardText(); not clip.isNil and $clip != app.lastClipboard):
app.win.setClipboardString(clip)
app.lastClipboard = $clip
proc render(app: var App) = # Called in the main loop
# Poll and handle events (inputs, window resize, etc.)
glfwPollEvents() # Use glfwWaitEvents() to only draw on events (more efficient)
# Start Dear ImGui Frame
igOpenGL3NewFrame()
igGlfwNewFrame()
igNewFrame()
# Draw application
app.drawMain()
# Render
igRender()
var displayW, displayH: int32
let bgColor = igColorConvertU32ToFloat4(uint32 WindowBg)
app.win.getFramebufferSize(displayW.addr, displayH.addr)
glViewport(0, 0, displayW, displayH)
glClearColor(bgColor.x, bgColor.y, bgColor.z, bgColor.w)
glClear(GL_COLOR_BUFFER_BIT)
igOpenGL3RenderDrawData(igGetDrawData())
app.win.makeContextCurrent()
app.win.swapBuffers()
proc initWindow(app: var App) =
glfwWindowHint(GLFWContextVersionMajor, 3)
glfwWindowHint(GLFWContextVersionMinor, 3)
glfwWindowHint(GLFWOpenglForwardCompat, GLFW_TRUE)
glfwWindowHint(GLFWOpenglProfile, GLFW_OPENGL_CORE_PROFILE)
glfwWindowHint(GLFWResizable, GLFW_TRUE)
app.win = glfwCreateWindow(
app.prefs["win"]["width"].getInt().int32,
app.prefs["win"]["height"].getInt().int32,
app.config["name"].getString().cstring,
icon = false, # Do not use default icon
)
if app.win == nil:
quit(-1)
# Set the window icon
var icon = initGLFWImage(app.config["iconPath"].getData().readImageFromMemory())
app.win.setWindowIcon(1, icon.addr)
app.win.setWindowSizeLimits(
app.config["minSize"][0].getInt().int32,
app.config["minSize"][1].getInt().int32,
GLFW_DONT_CARE,
GLFW_DONT_CARE,
) # minWidth, minHeight, maxWidth, maxHeight
# If negative pos, center the window in the first monitor
if app.prefs["win"]["x"].getInt() < 0 or app.prefs["win"]["y"].getInt() < 0:
var monitorX, monitorY, count: int32
let monitors = glfwGetMonitors(count.addr)
let videoMode = monitors[0].getVideoMode()
monitors[0].getMonitorPos(monitorX.addr, monitorY.addr)
app.win.setWindowPos(
monitorX + int32((videoMode.width - int app.prefs["win"]["width"].getInt()) / 2),
monitorY + int32((videoMode.height - int app.prefs["win"]["height"].getInt()) / 2),
)
else:
app.win.setWindowPos(
app.prefs["win"]["x"].getInt().int32, app.prefs["win"]["y"].getInt().int32
)
proc initPrefs(app: var App, path: string) =
app.prefs = initPrefs(
path = path,
default = toToml {
win: {
x: -1, # Negative numbers center the window
y: -1,
width: 1500,
height: 700,
},
currentView: 1,
currentTheme: 0,
currentSort: 0,
themes: toTTables [classicTheme, darkTheme, lightTheme, cherryTheme],
starred: [],
},
)
proc initApp(config: TomlValueRef): App =
result = App(
config: config,
cache: newTTable(),
currentView: -1,
hoveredView: -1,
currentTheme: -1,
sizesBuffer: newString(32),
colorsBuffer: newString(32),
previewBuffer: newString(64),
browseBuffer: newString(64),
previewProgressDir: 1f,
)
let prefsPath =
(result.getCacheDir() / result.config["name"].getString()).changeFileExt("toml")
try:
result.initPrefs(prefsPath)
except:
let m = messageBox(
result.config["name"].getString(),
&"Corrupt preferences file {prefsPath}.\nYou cannot continue using the app until it is fixed.\nYou may fix it manually or do you want to delete it and reset its content? You cannot undo this action",
DialogType.OkCancel,
IconType.Error,
Button.No,
)
if m == Button.Yes:
discard tryRemoveFile(prefsPath)
result.initPrefs(prefsPath)
else:
raise
result.updatePrefs()
result.initConfig(result.config["settings"])
result.downloader = initDownloader(result.getCacheDir())
result.switchTheme(int result.prefs["currentTheme"].getInt())
result.currentSort = int result.prefs["currentSort"].getInt()
result.currentView = int result.prefs["currentView"].getInt()
proc terminate(app: var App) =
var x, y, width, height: int32
app.win.getWindowPos(x.addr, y.addr)
app.win.getWindowSize(width.addr, height.addr)
app.prefs{"win", "x"} = x
app.prefs{"win", "y"} = y
app.prefs{"win", "width"} = width
app.prefs{"win", "height"} = height
app.prefs["currentView"] = app.currentView
app.prefs["currentSort"] = app.currentSort
app.prefs["currentTheme"] = app.currentTheme
app.prefs.save()
proc main() =
var app = initApp(Toml.decode(configPath.getData(), TomlValueRef))
# Setup Window
doAssert glfwInit()
app.initWindow()
app.win.makeContextCurrent()
glfwSwapInterval(1) # Enable vsync
doAssert glInit()
# Setup Dear ImGui context
igCreateContext()
let io = igGetIO()
io.iniFilename = nil # Disable .ini config file
# Setup Dear ImGui style using ImStyle
setStyleFromToml(Toml.decode(app.config["stylePath"].getData(), TomlValueRef))
# Setup Platform/Renderer backends
doAssert igGlfwInitForOpenGL(app.win, true)
doAssert igOpenGL3Init()
# Load fonts
app.font = io.fonts.igAddFontFromMemoryTTF(
app.config["fontPath"].getData(), app.config["fontSize"].getFloat()
)
# Merge ForkAwesome icon font
var config = utils.newImFontConfig(mergeMode = true)
var ranges = [FA_Min.uint16, FA_Max.uint16]
io.fonts.igAddFontFromMemoryTTF(
app.config["iconFontPath"].getData(),
app.config["fontSize"].getFloat(),
config.addr,
ranges[0].addr,
)
app.strongFont = io.fonts.igAddFontFromMemoryTTF(
app.config["strongFontPath"].getData(), app.config["fontSize"].getFloat() + 2
)
io.fonts.igAddFontFromMemoryTTF(
app.config["iconFontPath"].getData(),
app.config["fontSize"].getFloat() + 2,
config.addr,
ranges[0].addr,
)
app.sidebarIconFont = io.fonts.igAddFontFromMemoryTTF(
app.config["iconFontPath"].getData(),
app.config["fontSize"].getFloat() + 18,
glyph_ranges = ranges[0].addr,
)
# Main loop
while not app.win.windowShouldClose:
app.render()
# Cleanup
igOpenGL3Shutdown()
igGlfwShutdown()
igDestroyContext()
app.terminate()
app.win.destroyWindow()
glfwTerminate()
when isMainModule:
main()