-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathSlabTest.lua
2550 lines (1989 loc) · 83.1 KB
/
SlabTest.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
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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
MIT License
Copyright (c) 2019-2021 Love2D Community <love2d.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
local Slab = require(SLAB_PATH .. '.Slab')
local SlabDebug = require(SLAB_PATH .. '.SlabDebug')
local SlabTest = {}
local function DrawOverview()
Slab.Textf(
"Slab is an immediate mode GUI toolkit for the LÖVE 2D framework. This library " ..
"is designed to allow users to easily add this library to their existing LÖVE 2D projects and " ..
"quickly create tools to enable them to iterate on their ideas quickly. The user should be able " ..
"to utilize this library with minimal integration steps and is completely written in Lua and utilizes " ..
"the LÖVE 2D API. No compiled binaries are required and the user will have access to the source so " ..
"that they may make adjustments that meet the needs of their own projects and tools. Refer to main.lua " ..
"and SlabTest.lua for example usage of this library.\n\n" ..
"This window will demonstrate the usage of the Slab library and give an overview of all the supported controls " ..
"and features.")
Slab.NewLine()
Slab.Text("The current version of Slab is: ")
Slab.SameLine()
Slab.Text(Slab.GetVersion(), {Color = {0, 1, 0, 1}})
Slab.Text("The current version of LÖVE is: ")
Slab.SameLine()
Slab.Text(Slab.GetLoveVersion(), {Color = {0, 1, 0, 1}})
Slab.Text("The current OS is: ")
Slab.SameLine()
Slab.Text(love.system.getOS(), {Color = {0, 1, 0, 1}})
end
local DrawButtons_NumClicked = 0
local DrawButtons_NumClicked_Invisible = 0
local DrawButtons_Enabled = false
local DrawButtons_Hovered = false
local function DrawButtons()
Slab.Textf("Buttons are simple controls which respond to a user's left mouse click. Buttons will simply return true when they are clicked.")
Slab.NewLine()
if Slab.Button("Button") then
DrawButtons_NumClicked = DrawButtons_NumClicked + 1
end
Slab.SameLine()
Slab.Text("You have clicked this button " .. DrawButtons_NumClicked .. " time(s).")
Slab.NewLine()
Slab.Separator()
Slab.Textf("Buttons can be tested for mouse hover with the call to Slab.IsControlHovered right after declaring the button.")
Slab.Button(DrawButtons_Hovered and "Hovered" or "Not Hovered", {W = 100})
DrawButtons_Hovered = Slab.IsControlHovered()
Slab.NewLine()
Slab.Separator()
Slab.Textf("Buttons can have a custom width and height.")
Slab.Button("Square", {W = 75, H = 75})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Buttons can also be invisible so that the designer can implement a custom button but still rely on the " ..
"button behavior. Below is a an invisible button and a custom rectangle drawn at the same location.")
local X, Y = Slab.GetCursorPos()
Slab.Rectangle({Mode = 'line', W = 50.0, H = 50.0, Color = {1, 1, 1, 1}})
Slab.SetCursorPos(X, Y)
if Slab.Button("", {Invisible = true, W = 50.0, H = 50.0}) then
DrawButtons_NumClicked_Invisible = DrawButtons_NumClicked_Invisible + 1
end
Slab.SameLine({CenterY = true})
Slab.Text("Invisible button has been clicked " .. DrawButtons_NumClicked_Invisible .. " time(s).")
Slab.NewLine()
Slab.Separator()
Slab.Textf("Buttons can also be disabled. Click the button below to toggle the status of the neighboring button.")
if Slab.Button("Toggle", { Active = DrawButtons_Enabled }) then
DrawButtons_Enabled = not DrawButtons_Enabled
end
Slab.SameLine()
Slab.Button(DrawButtons_Enabled and "Enabled" or "Disabled", {Disabled = not DrawButtons_Enabled})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Buttons can also display images instead of a text label. This can be down through the 'Image' option, which accepts a table " ..
"where the options are the same as those found in the 'Image' API function.")
Slab.Button("", {Image = {Path = SLAB_FILE_PATH .. "/Internal/Resources/Textures/avatar.png"}})
end
local DrawText_Width = 450.0
local DrawText_Height = 0.0
local DrawText_Alignment = {'left', 'center', 'right', 'justify'}
local DrawText_Alignment_Selected = 'left'
local DrawText_NumClicked = 0
local DrawText_NumClicked_TextOnly = 0
local function DrawText()
Slab.Textf("Text controls displays text on the current window. Slab currently offers three ways to control the text.")
Slab.NewLine()
Slab.Separator()
Slab.Text("The most basic text control is Slab.Text.")
Slab.Text("The color of the text can be controlled with the 'Color' option.", {Color = {0, 1, 0, 1}})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Text can be formatted using the Slab.Textf API. Formatted text will wrap the text based on the 'W' option. " ..
"If the 'W' option is not specified, the window's width will be used as the width. Formatted text also has an " ..
"alignment option. The 'H' option can be used to center the text within a given height.")
Slab.NewLine()
Slab.Text("Width")
Slab.SameLine()
if Slab.Input('DrawText_Width', {Text = tostring(DrawText_Width), NumbersOnly = true, ReturnOnText = false}) then
DrawText_Width = Slab.GetInputNumber()
end
Slab.SameLine()
Slab.Text("Height")
Slab.SameLine()
if Slab.Input('DrawText_Height', {Text = tostring(DrawText_Height), NumbersOnly = true, ReturnOnText = false}) then
DrawText_Height = Slab.GetInputNumber()
end
Slab.SameLine()
Slab.Text("Alignment")
Slab.SameLine()
if Slab.BeginComboBox('DrawText_Alignment', {Selected = DrawText_Alignment_Selected}) then
for I, V in ipairs(DrawText_Alignment) do
if Slab.TextSelectable(V) then
DrawText_Alignment_Selected = V
end
end
Slab.EndComboBox()
end
Slab.Textf(
"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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " ..
"dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " ..
"officia deserunt mollit anim id est laborum.", {W = DrawText_Width, H = DrawText_Height, Align = DrawText_Alignment_Selected})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Text can also be interacted with using the Slab.TextSelectable function. A background will be " ..
"rendered when the mouse is hovered over the text and the function will return true when clicked on. " ..
"The selectable area expands to the width of the window by default. This can be changed to just the text " ..
"with the 'IsSelectableTextOnly' option.")
Slab.NewLine()
if Slab.TextSelectable("This text has been clicked " .. DrawText_NumClicked .. " time(s).") then
DrawText_NumClicked = DrawText_NumClicked + 1
end
Slab.NewLine()
if Slab.TextSelectable("This text has been clicked " .. DrawText_NumClicked_TextOnly .. " time(s).", {IsSelectableTextOnly = true}) then
DrawText_NumClicked_TextOnly = DrawText_NumClicked_TextOnly + 1
end
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Text controls can be configured to contain URL links. When this control is clicked, Slab will open the given URL " ..
"with the user's default web browser.")
Slab.Text("Love 2D", {URL = "http://love2d.org"})
end
local DrawCheckBox_Checked = false
local DrawCheckBox_Checked_NoLabel = false
local function DrawCheckBox()
Slab.Textf(
"Check boxes are controls that will display an empty box with an optional label. The function will " ..
"return true if the user has clicked on the box. The code is then responsible for updating the checked " ..
"flag to be passed back into the function.")
Slab.NewLine()
if Slab.CheckBox(DrawCheckBox_Checked, "Check Box") then
DrawCheckBox_Checked = not DrawCheckBox_Checked
end
Slab.NewLine()
Slab.Text("A check box with no label.")
if Slab.CheckBox(DrawCheckBox_Checked_NoLabel) then
DrawCheckBox_Checked_NoLabel = not DrawCheckBox_Checked_NoLabel
end
Slab.NewLine()
Slab.Text("A disabled check box.")
Slab.CheckBox(true, "Disabled", {Disabled = true})
end
local DrawRadioButton_Selected = 1
local function DrawRadioButton()
Slab.Textf("Radio buttons offer the user to select one option from a list of options.")
Slab.NewLine()
for I = 1, 5, 1 do
if Slab.RadioButton("Option " .. I, {Index = I, SelectedIndex = DrawRadioButton_Selected}) then
DrawRadioButton_Selected = I
end
end
end
local DrawMenus_Window_Selected = "Right click and select an option."
local DrawMenus_Control_Selected = "Right click and select an option from a control."
local DrawMenus_CheckBox = false
local DrawMenus_ComboBox = {"Apple", "Banana", "Pear", "Orange", "Lemon"}
local DrawMenus_ComboBox_Selected = "Apple"
local function DrawContextMenuItem(Label, Button)
if Slab.BeginContextMenuItem(Button) then
for I = 1, 5, 1 do
local MenuLabel = Label .. " Option " .. I
if Slab.MenuItem(MenuLabel) then
DrawMenus_Control_Selected = MenuLabel
end
end
Slab.EndContextMenu()
end
end
local function DrawMenus()
Slab.Textf(
"Menus are windows that allow users to make a selection from a list of items. Items can be disabled to prevent " ..
"any interaction but will still be displayed. Below are descriptions of the various menus and how they can be utilized.")
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"The main menu bar is rendered at the top of the window with menu items being added " ..
"from left to right. When a menu item is clicked, a context menu is opened below the " ..
"selected item. Creating the main menu bar can open anywhere in the code after the " ..
"Slab.Update call. These functions should not be called within a BeginWindow/EndWindow " ..
"call.")
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Context menus are menus which are rendered above all other controls to allow the user to make a selection " ..
"out of a list of items. These can be opened up through the menu bar, or through a right-click " ..
"action from the user on a given window or control. Menus and menu items make up the context menu " ..
"and menus can be nested to allow a tree options to be displayed.")
Slab.NewLine()
Slab.Textf(
"Controls can have their own context menus. Right-click on each control to open up the menu " ..
"and select an option.")
Slab.NewLine()
Slab.Text(DrawMenus_Control_Selected)
Slab.NewLine()
Slab.Button("Button")
DrawContextMenuItem("Button")
Slab.Text("Text")
DrawContextMenuItem("Text")
if Slab.CheckBox(DrawMenus_CheckBox, "Check Box") then
DrawMenus_CheckBox = not DrawMenus_CheckBox
end
DrawContextMenuItem("Check Box")
Slab.Input('DrawMenus_Input')
DrawContextMenuItem("Input")
if Slab.BeginComboBox('DrawMenus_ComboBox', {Selected = DrawMenus_ComboBox_Selected}) then
for I, V in ipairs(DrawMenus_ComboBox) do
if Slab.TextSelectable(V) then
DrawMenus_Window_Selected = V
end
end
Slab.EndComboBox()
end
DrawContextMenuItem("Combo Box")
Slab.NewLine()
Slab.Textf(
"Context menu items are usually opened with the right mouse button. This can be changed for context menus to be a differen " ..
"mouse button. The button below will open a context menu using the left mouse button.")
Slab.NewLine()
Slab.Button("Left Mouse")
DrawContextMenuItem("Left Mouse Button", 1)
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Right-clicking anywhere within this window will open up a context menu. Note that BeginContextMenuWindow " ..
"must come after all BeginContextMenuItem calls.")
Slab.NewLine()
Slab.Textf(DrawMenus_Window_Selected)
if Slab.BeginContextMenuWindow() then
if Slab.BeginMenu("Window Menu 1") then
for I = 1, 5, 1 do
local Enabled = I % 2 ~= 0
if Slab.MenuItem("Sub Window Option " .. I, {Enabled = Enabled}) then
DrawMenus_Window_Selected = "Sub Window Option " .. I
end
end
Slab.EndMenu()
end
for I = 1, 5, 1 do
if Slab.MenuItem("Window Option " .. I) then
DrawMenus_Window_Selected = "Window Option " .. I .. " selected."
end
end
Slab.EndContextMenu()
end
end
local DrawComboBox_Options = {"England", "France", "Germany", "USA", "Canada", "Mexico", "Japan", "South Korea", "China", "Russia", "India"}
local DrawComboBox_Selected = "USA"
local DrawComboBox_Selected_Width = "USA"
local function DrawComboBox()
Slab.Textf(
"A combo box allows the user to select a single item from a list and display the selected item " ..
"in the combo box. The list is only visible when the user is interacting with the control.")
Slab.NewLine()
if Slab.BeginComboBox('DrawComboBox_One', {Selected = DrawComboBox_Selected}) then
for I, V in ipairs(DrawComboBox_Options) do
if Slab.TextSelectable(V) then
DrawComboBox_Selected = V
end
end
Slab.EndComboBox()
end
Slab.NewLine()
Slab.Separator()
Slab.Textf("A combo box's width can be modified with the 'W' option.")
Slab.NewLine()
local W, H = Slab.GetWindowActiveSize()
if Slab.BeginComboBox('DrawComboBox_Two', {Selected = DrawComboBox_Selected_Width, W = W}) then
for I, V in ipairs(DrawComboBox_Options) do
if Slab.TextSelectable(V) then
DrawComboBox_Selected_Width = V
end
end
Slab.EndComboBox()
end
end
local DrawInput_Basic = "Hello World"
local DrawInput_Basic_Return = "Hello World"
local DrawInput_Basic_Numbers = 0
local DrawInput_Basic_Numbers_Clamped = 0.5
local DrawInput_Basic_Numbers_Clamped_Min = 0.0
local DrawInput_Basic_Numbers_Clamped_Max = 1.0
local DrawInput_Basic_Numbers_Clamped_Step = 0.01
local DrawInput_Basic_Numbers_NoDrag = 50
local DrawInput_Basic_Numbers_Slider = 50
local DrawInput_Basic_Numbers_Slider_Handle = 50
local DrawInput_Basic_Numbers_Slider_Min = 0
local DrawInput_Basic_Numbers_Slider_Max = 100
local DrawInput_MultiLine =
[[
function Foo()
print("Bar")
end
The quick brown fox jumped over the lazy dog.]]
local DrawInput_MultiLine_Width = math.huge
local DrawInput_CursorPos = 0
local DrawInput_CursorColumn = 0
local DrawInput_CursorLine = 0
local DrawInput_Highlight_Text =
[[
function Hello()
print("World")
end]]
local DrawInput_Highlight_Table = {
['function'] = {1, 0, 0, 1},
['end'] = {0, 0, 1, 1}
}
local DrawInput_Highlight_Table_Modify = nil
local function DrawInput()
Slab.Textf(
"The input control allows the user to enter in text into an input box. This control is similar " ..
"to input boxes found in other applications. These controls are set up to handle UTF8 characters.")
Slab.NewLine()
Slab.Textf(
"The first example is very simple. An Input control is declared and the resulting text is captured if " ..
"the function returns true. By default, the function will return true on any text that is entered.")
if Slab.Input('DrawInput_Basic', {Text = DrawInput_Basic}) then
DrawInput_Basic = Slab.GetInputText()
end
Slab.NewLine()
Slab.Textf(
"The return behavior can be modified so that the function will only return true if the Enter/Return " ..
"key is pressed. If the control loses focus without the Enter/Return key pressed, then the text will " ..
"revert back to what it was before.")
if Slab.Input('DrawInput_Basic_Return', {Text = DrawInput_Basic_Return, ReturnOnText = false}) then
DrawInput_Basic_Return = Slab.GetInputText()
end
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Input controls can be configured to only take numeric values. Input controls that are configured this way " ..
"will allow the user to click and drag the control to alter the value by default. The user must double-click the "..
"control to manually enter a valid number.")
if Slab.Input('DrawInput_Basic_Numbers', {Text = tostring(DrawInput_Basic_Numbers), NumbersOnly = true}) then
DrawInput_Basic_Numbers = Slab.GetInputNumber()
end
Slab.NewLine()
Slab.Textf(
"These numeric controls can also have min and/or max values set. Below is an example where the " ..
"numeric input control is clamped from 0.0 to 1.0. The drag step is also modified to be smaller for more precision.")
Slab.Text("Min")
Slab.SameLine()
local DrawInput_Basic_Numbers_Clamped_Min_Options =
{
Text = tostring(DrawInput_Basic_Numbers_Clamped_Min),
MaxNumber = DrawInput_Basic_Numbers_Clamped_Max,
Step = DrawInput_Basic_Numbers_Clamped_Step,
NumbersOnly = true,
W = 50
}
if Slab.Input('DrawInput_Basic_Numbers_Clamped_Min', DrawInput_Basic_Numbers_Clamped_Min_Options) then
DrawInput_Basic_Numbers_Clamped_Min = Slab.GetInputNumber()
end
Slab.SameLine()
Slab.Text("Max")
Slab.SameLine()
local DrawInput_Basic_Numbers_Clamped_Max_Options =
{
Text = tostring(DrawInput_Basic_Numbers_Clamped_Max),
MinNumber = DrawInput_Basic_Numbers_Clamped_Min,
Step = DrawInput_Basic_Numbers_Clamped_Step,
NumbersOnly = true,
W = 50
}
if Slab.Input('DrawInput_Basic_Numbers_Clamped_Max', DrawInput_Basic_Numbers_Clamped_Max_Options) then
DrawInput_Basic_Numbers_Clamped_Max = Slab.GetInputNumber()
end
Slab.SameLine()
Slab.Text("Step")
Slab.SameLine()
local DrawInput_Basic_Numbers_Clamped_Step_Options =
{
Text = tostring(DrawInput_Basic_Numbers_Clamped_Step),
MinNumber = 0,
Step = 0.01,
NumbersOnly = true,
W = 50
}
if Slab.Input('DrawInput_Basic_Numbers_Clamped_Step', DrawInput_Basic_Numbers_Clamped_Step_Options) then
DrawInput_Basic_Numbers_Clamped_Step = Slab.GetInputNumber()
end
local DrawInput_Basic_Numbers_Clamped_Options =
{
Text = tostring(DrawInput_Basic_Numbers_Clamped),
NumbersOnly = true,
MinNumber = DrawInput_Basic_Numbers_Clamped_Min,
MaxNumber = DrawInput_Basic_Numbers_Clamped_Max,
Step = DrawInput_Basic_Numbers_Clamped_Step
}
if Slab.Input('DrawInput_Basic_Numbers_Clamped', DrawInput_Basic_Numbers_Clamped_Options) then
DrawInput_Basic_Numbers_Clamped = Slab.GetInputNumber()
end
Slab.NewLine()
Slab.Textf(
"The click and drag functionality of numeric controls can also be disabled. This will make the input control behave like a " ..
"standard text input control.")
if Slab.Input('DrawInput_Basic_Numbers_NoDrag', {Text = tostring(DrawInput_Basic_Numbers_NoDrag), NumbersOnly = true, NoDrag = true}) then
DrawInput_Basic_Numbers_NoDrag = Slab.GetInputNumber()
end
Slab.NewLine()
Slab.Textf(
"A slider can also be used for these numeric input controls. When configured this way, the value is altered based on where the " ..
"user clicks and drags inside the control.")
Slab.Text("Min")
Slab.SameLine()
if Slab.InputNumberDrag('DrawInput_Basic_Numbers_Slider_Min', DrawInput_Basic_Numbers_Slider_Min, nil, DrawInput_Basic_Numbers_Slider_Max, nil, {W = 50}) then
DrawInput_Basic_Numbers_Slider_Min = Slab.GetInputNumber()
end
Slab.SameLine()
Slab.Text("Max")
Slab.SameLine()
if Slab.InputNumberDrag('DrawInput_Basic_Numbers_Slider_Max', DrawInput_Basic_Numbers_Slider_Max, DrawInput_Basic_Numbers_Slider_Min, nil, nil, {W = 50}) then
DrawInput_Basic_Numbers_Slider_Max = Slab.GetInputNumber()
end
if Slab.InputNumberSlider('DrawInput_Basic_Numbers_Slider', DrawInput_Basic_Numbers_Slider, DrawInput_Basic_Numbers_Slider_Min, DrawInput_Basic_Numbers_Slider_Max) then
DrawInput_Basic_Numbers_Slider = Slab.GetInputNumber()
end
Slab.NewLine()
Slab.Text("Sliders can also be drawn with a handle")
if Slab.InputNumberSlider('DrawInput_Basic_Numbers_Slider_Handle', DrawInput_Basic_Numbers_Slider_Handle, DrawInput_Basic_Numbers_Slider_Min, DrawInput_Basic_Numbers_Slider_Max, {DrawSliderAsHandle = true}) then
DrawInput_Basic_Numbers_Slider_Handle = Slab.GetInputNumber()
end
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Input controls also allow for multi-line editing using the MultiLine option. The default text wrapping " ..
"option is set to math.huge, but this can be modified with the MultiLineW option. The example below demonstrates " ..
"how to set up a multi-line input control and shows how the size of the control can be modified.")
Slab.NewLine()
Slab.Text("MultiLineW")
Slab.SameLine()
if Slab.Input('DrawInput_MultiLine_Width', {Text = tostring(DrawInput_MultiLine_Width), NumbersOnly = true, ReturnOnText = false}) then
DrawInput_MultiLine_Width = Slab.GetInputNumber()
end
Slab.SameLine()
Slab.Text("Cursor Pos")
Slab.SameLine()
if Slab.Input('DrawInput_CursorPos', {Text = tostring(DrawInput_CursorPos), NumbersOnly = true, ReturnOnText = false, MinNumber = 0, W = 75}) then
DrawInput_CursorPos = Slab.GetInputNumber()
Slab.SetInputFocus('DrawInput_MultiLine')
Slab.SetInputCursorPos(DrawInput_CursorPos)
end
Slab.SameLine()
Slab.Text("Column")
Slab.SameLine()
if Slab.Input('DrawInput_CursorColumn', {Text = tostring(DrawInput_CursorColumn), NumbersOnly = true, ReturnOnText = false, MinNumber = 0, W = 75}) then
DrawInput_CursorColumn = Slab.GetInputNumber()
Slab.SetInputFocus('DrawInput_MultiLine')
Slab.SetInputCursorPosLine(DrawInput_CursorColumn, DrawInput_CursorLine)
end
Slab.SameLine()
Slab.Text("Line")
Slab.SameLine()
if Slab.Input('DrawInput_CursorLine', {Text = tostring(DrawInput_CursorLine), NumbersOnly = true, ReturnOnText = false, MinNumber = 0, W = 75}) then
DrawInput_CursorLine = Slab.GetInputNumber()
Slab.SetInputFocus('DrawInput_MultiLine')
Slab.SetInputCursorPosLine(DrawInput_CursorColumn, DrawInput_CursorLine)
end
local W, H = Slab.GetWindowActiveSize()
if Slab.Input('DrawInput_MultiLine', {Text = DrawInput_MultiLine, MultiLine = true, MultiLineW = DrawInput_MultiLine_Width, W = W, H = 150.0}) then
DrawInput_MultiLine = Slab.GetInputText()
end
if Slab.IsInputFocused('DrawInput_MultiLine') then
DrawInput_CursorPos, DrawInput_CursorColumn, DrawInput_CursorLine = Slab.GetInputCursorPos()
end
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"The input control also offers a way to highlight certain words with a custom color. Below is a list of keywords and the color used to define the word.")
Slab.NewLine()
local TextW, TextH = Slab.GetTextSize("")
for K, V in pairs(DrawInput_Highlight_Table) do
if Slab.Input('DrawInput_Highlight_Table_' .. K, {Text = K, ReturnOnText = false}) then
DrawInput_Highlight_Table[K] = nil
K = Slab.GetInputText()
DrawInput_Highlight_Table[K] = V
end
Slab.SameLine({Pad = 20.0})
Slab.Rectangle({W = 50, H = TextH, Color = V})
if Slab.IsControlClicked() then
DrawInput_Highlight_Table_Modify = K
end
Slab.SameLine({Pad = 20.0})
if Slab.Button("Delete", {H = TextH}) then
DrawInput_Highlight_Table[K] = nil
end
end
if Slab.Button("Add") then
DrawInput_Highlight_Table['new'] = {1, 0, 0, 1}
end
if DrawInput_Highlight_Table_Modify ~= nil then
local Result = Slab.ColorPicker({Color = DrawInput_Highlight_Table[DrawInput_Highlight_Table_Modify]})
if Result.Button ~= 0 then
if Result.Button == 1 then
DrawInput_Highlight_Table[DrawInput_Highlight_Table_Modify] = Result.Color
end
DrawInput_Highlight_Table_Modify = nil
end
end
Slab.NewLine()
if Slab.Input('DrawInput_Highlight', {Text = DrawInput_Highlight_Text, MultiLine = true, Highlight = DrawInput_Highlight_Table, W = W, H = 150.0}) then
DrawInput_Highlight_Text = Slab.GetInputText()
end
end
local DrawImage_Path = SLAB_FILE_PATH .. "/Internal/Resources/Textures/avatar.png"
local DrawImage_Path_Icons = SLAB_FILE_PATH .. "/Internal/Resources/Textures/Icons.png"
local DrawImage_Color = {1, 0, 0, 1}
local DrawImage_Color_Edit = false
local DrawImage_Scale = 1.0
local DrawImage_Scale_X = 1.0
local DrawImage_Scale_Y = 1.0
local DrawImage_Power = false
local DrawImage_Power_Hovered = false
local DrawImage_Power_On = {0, 1, 0, 1}
local DrawImage_Power_Off = {1, 0, 0, 1}
local DrawImage_Icon_X = 0
local DrawImage_Icon_Y = 0
local DrawImage_Icon_Move = false
local DrawImage_UseOutline = true
local DrawImage_OutlineWidth = 1
local DrawImage_OutlineColor = {0, 0, 0, 1}
local DrawImage_OutlineColor_Edit = false
local function DrawImage()
Slab.Textf(
"Images can be drawn within windows and react to user interaction. A path to an image can be specified through the options of " ..
"the Image function. If this is done, Slab will manage the image resource and will use the path as a key to the resource.")
Slab.Image('DrawImage_Basic', {Path = DrawImage_Path})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"An image's color can be modified with the 'Color' option.")
if Slab.Button("Change Color") then
DrawImage_Color_Edit = true
end
if DrawImage_Color_Edit then
local Result = Slab.ColorPicker({Color = DrawImage_Color})
if Result.Button ~= 0 then
DrawImage_Color_Edit = false
if Result.Button == 1 then
DrawImage_Color = Result.Color
end
end
end
Slab.Image('DrawImage_Color', {Path = DrawImage_Path, Color = DrawImage_Color})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"An outline can be applied to the image. The color and width of the outline is customizable.")
Slab.Text("Use Outline")
Slab.SameLine()
if Slab.CheckBox(DrawImage_UseOutline) then
DrawImage_UseOutline = not DrawImage_UseOutline
end
Slab.SameLine()
Slab.Text("Width")
Slab.SameLine()
if Slab.Input('DrawImage_OutlineWidth', {Text = DrawImage_OutlineWidth, NumbersOnly = true, ReturnOnText = false, MinNumber = 1}) then
DrawImage_OutlineWidth = Slab.GetInputNumber()
end
Slab.SameLine()
if Slab.Button("Color") then
DrawImage_OutlineColor_Edit = true
end
if DrawImage_OutlineColor_Edit then
local Result = Slab.ColorPicker({Color = DrawImage_OutlineColor})
if Result.Button ~= 0 then
DrawImage_OutlineColor_Edit = false
if Result.Button == 1 then
DrawImage_OutlineColor = Result.Color
end
end
end
Slab.Image('DrawImage_Outline', {Path = DrawImage_Path, UseOutline = DrawImage_UseOutline, OutlineW = DrawImage_OutlineWidth, OutlineColor = DrawImage_OutlineColor})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"There is an option to modify the scale of an image. The scale can both be affected " ..
"on the X or Y axis.")
Slab.Text("Scale")
Slab.SameLine()
if Slab.Input('DrawImage_Scale', {Text = tostring(DrawImage_Scale), NumbersOnly = true, ReturnOnText = false, W = 75}) then
DrawImage_Scale = Slab.GetInputNumber()
DrawImage_Scale_X = DrawImage_Scale
DrawImage_Scale_Y = DrawImage_Scale
end
Slab.SameLine({Pad = 6.0})
Slab.Text("Scale X")
Slab.SameLine()
if Slab.Input('DrawImage_Scale_X', {Text = tostring(DrawImage_Scale_X), NumbersOnly = true, ReturnOnText = false, W = 75}) then
DrawImage_Scale_X = Slab.GetInputNumber()
end
Slab.SameLine({Pad = 6.0})
Slab.Text("Scale Y")
Slab.SameLine()
if Slab.Input('DrawImage_Scale_Y', {Text = tostring(DrawImage_Scale_Y), NumbersOnly = true, ReturnOnText = false, W = 75}) then
DrawImage_Scale_Y = Slab.GetInputNumber()
end
Slab.Image('DrawImage_Scale', {Path = DrawImage_Path, ScaleX = DrawImage_Scale_X, ScaleY = DrawImage_Scale_Y})
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Images can also have interactions through the control API. The left image will change when the mouse is hovered " ..
"while the right image will change on click.")
Slab.Image('DrawImage_Hover', {Path = DrawImage_Path, Color = DrawImage_Power_Hovered and DrawImage_Power_On or DrawImage_Power_Off})
DrawImage_Power_Hovered = Slab.IsControlHovered()
Slab.SameLine({Pad = 12.0})
Slab.Image('DrawImage_Click', {Path = DrawImage_Path, Color = DrawImage_Power and DrawImage_Power_On or DrawImage_Power_Off})
if Slab.IsControlClicked() then
DrawImage_Power = not DrawImage_Power
end
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"A sub region can be defined to draw a section of an image. Move the rectangle around and observe the image on the right.")
local X, Y = Slab.GetCursorPos()
local AbsX, AbsY = Slab.GetCursorPos({Absolute = true})
Slab.Image('DrawImage_Icons', {Path = DrawImage_Path_Icons})
if Slab.IsControlClicked() then
local MouseX, MouseY = Slab.GetMousePositionWindow()
local Left = AbsX + DrawImage_Icon_X
local Right = Left + 50.0
local Top = AbsY + DrawImage_Icon_Y
local Bottom = Top + 50.0
if Left <= MouseX and MouseX <= Right and
Top <= MouseY and MouseY <= Bottom then
DrawImage_Icon_Move = true
end
end
if Slab.IsMouseReleased() then
DrawImage_Icon_Move = false
end
local W, H = Slab.GetControlSize()
if DrawImage_Icon_Move then
local DeltaX, DeltaY = Slab.GetMouseDelta()
DrawImage_Icon_X = math.max(DrawImage_Icon_X + DeltaX, 0.0)
DrawImage_Icon_X = math.min(DrawImage_Icon_X, W - 50.0)
DrawImage_Icon_Y = math.max(DrawImage_Icon_Y + DeltaY, 0.0)
DrawImage_Icon_Y = math.min(DrawImage_Icon_Y, H - 50.0)
end
Slab.SetCursorPos(X + DrawImage_Icon_X, Y + DrawImage_Icon_Y)
Slab.Rectangle({Mode = 'line', Color = {0, 0, 0, 1}, W = 50.0, H = 50.0})
Slab.SetCursorPos(X + W + 12.0, Y)
Slab.Image('DrawImage_Icons_Region', {
Path = DrawImage_Path_Icons,
SubX = DrawImage_Icon_X,
SubY = DrawImage_Icon_Y,
SubW = 50.0,
SubH = 50.0
})
end
local DrawCursor_NewLines = 1
local DrawCursor_SameLinePad = 4.0
local DrawCursor_X = nil
local DrawCursor_Y = nil
local DrawCursor_Indent = 14
local function DrawCursor()
Slab.Textf(
"Slab offers a way to manage the drawing of controls through the cursor. Whenever a control is used, the cursor is "..
"automatically advanced based on the size of the control. By default, cursors are advanced vertically downward based " ..
"on the control's height. However, functions are provided to move the cursor back up to the previous line or create " ..
"an empty line to advance the cursor downward.")
for I = 1, DrawCursor_NewLines, 1 do
Slab.NewLine()
end
Slab.Textf(
"There is a new line between this text and the above description. Modify the number of new lines using the " ..
"input box below.")
if Slab.Input('DrawCursor_NewLines', {Text = tostring(DrawCursor_NewLines), NumbersOnly = true, ReturnOnText = false, MinNumber = 0}) then
DrawCursor_NewLines = Slab.GetInputNumber()
end
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Using the SameLine function, controls can be layed out on a single line with additional padding. Below are two buttons on " ..
"the same line with some padding. Use the input field below to modify the padding.")
Slab.Button("One")
Slab.SameLine({Pad = DrawCursor_SameLinePad})
Slab.Button("Two")
if Slab.Input('DrawCursor_SameLinePad', {Text = tostring(DrawCursor_SameLinePad), NumbersOnly = true, ReturnOnText = false}) then
DrawCursor_SameLinePad = Slab.GetInputNumber()
end
Slab.NewLine()
Slab.Textf(
"The SameLine function can also vertically center the next item based on the previous control. This is useful for labeling " ..
"items that are much bigger than the text such as images.")
Slab.Image('DrawCursor_Image', {Path = DrawImage_Path})
Slab.SameLine({CenterY = true})
Slab.Text("This text is centered with respect to the previous image.")
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"Slab offers functions to retrieve and set the cursor position. The GetCursorPos function will return the cursor position " ..
"relative to the current window. An option can be passed to retrieve the absolute position of the cursor with respect " ..
"to the viewport.")
local X, Y = Slab.GetCursorPos()
Slab.Text("Cursor X: " .. X)
Slab.SameLine()
Slab.Text("Cursor Y: " .. Y)
local AbsX, AbsY = Slab.GetCursorPos({Absolute = true})
Slab.Text("Absolute X: " .. AbsX)
Slab.SameLine()
Slab.Text("Absolute Y: " .. AbsY)
if DrawCursor_X == nil then
DrawCursor_X, DrawCursor_Y = Slab.GetCursorPos()
end
if Slab.Input('DrawCursor_X', {Text = tostring(DrawCursor_X), NumbersOnly = true, ReturnOnText = false}) then
DrawCursor_X = Slab.GetInputNumber()
end
Slab.SameLine()
if Slab.Input('DrawCursor_Y', {Text = tostring(DrawCursor_Y), NumbersOnly = true, ReturnOnText = false}) then
DrawCursor_Y = Slab.GetInputNumber()
end
Slab.SetCursorPos(DrawCursor_X, DrawCursor_Y + 30.0)
Slab.Text("Use the input fields to move this text.")
Slab.NewLine()
Slab.Separator()
Slab.Textf(
"There are also API functions to indent or unindent the anchored X position of the cursor. The function takes in a " ..
"number which represents how far to advance/retreat in pixels from the current anchored position. If no number is " ..
"given, then the default value is used which is defined by the Indent property located in the Style table. Below " ..
"are examples of how the Indent/Unindent functions can be used and while the example mainly uses Text controls, these " ..
"functions can be applied to any controls.")
Slab.NewLine()
Slab.Text("Line 1")
Slab.Text("Line 2")
Slab.Indent()
Slab.Text("Indented Line 1")
Slab.Text("Indented Line 2")
Slab.Indent()
Slab.Text("Indented Line 3")
Slab.Unindent()
Slab.Text("Unindented Line 1")
Slab.Text("Unindented Line 2")
Slab.Unindent()
Slab.Text("Unindented Line 3")
Slab.NewLine()
Slab.Indent(DrawCursor_Indent)
Slab.Text("Indent:")
Slab.SameLine()
if Slab.Input('DrawCursor_Indent', {Text = tostring(DrawCursor_Indent), NumbersOnly = true, ReturnOnText = false}) then
DrawCursor_Indent = Slab.GetInputNumber()
end
end
local DrawListBox_Basic_Selected = 1
local DrawListBox_Basic_Count = 10
local DrawListBox_Advanced_Selected = 1
local function DrawListBox()
Slab.Textf(
"A list box is a scrollable region that contains a list of elements that a user can interact with. The API is flexible " ..
"so that each element in the list can be rendered in any way desired. Below are a few examples on different ways a list " ..
"box can be used.")
Slab.NewLine()