-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
API.lua
2553 lines (1999 loc) · 81.8 KB
/
API.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.
--]]
if SLAB_PATH == nil then
SLAB_PATH = (...):match("(.-)[^%.]+$")
end
SLAB_FILE_PATH = debug.getinfo(1, 'S').source:match("^@(.+)/")
SLAB_FILE_PATH = SLAB_FILE_PATH == nil and "" or SLAB_FILE_PATH
local StatsData = {}
local PrevStatsData = {}
local Button = require(SLAB_PATH .. '.Internal.UI.Button')
local CheckBox = require(SLAB_PATH .. '.Internal.UI.CheckBox')
local ColorPicker = require(SLAB_PATH .. '.Internal.UI.ColorPicker')
local ComboBox = require(SLAB_PATH .. '.Internal.UI.ComboBox')
local Config = require(SLAB_PATH .. '.Internal.Core.Config')
local Cursor = require(SLAB_PATH .. '.Internal.Core.Cursor')
local Scale = require(SLAB_PATH .. ".Internal.Core.Scale")
local Dialog = require(SLAB_PATH .. '.Internal.UI.Dialog')
local Dock = require(SLAB_PATH .. '.Internal.UI.Dock')
local DrawCommands = require(SLAB_PATH .. '.Internal.Core.DrawCommands')
local FileSystem = require(SLAB_PATH .. '.Internal.Core.FileSystem')
local Image = require(SLAB_PATH .. '.Internal.UI.Image')
local Input = require(SLAB_PATH .. '.Internal.UI.Input')
local Keyboard = require(SLAB_PATH .. '.Internal.Input.Keyboard')
local LayoutManager = require(SLAB_PATH .. '.Internal.UI.LayoutManager')
local ListBox = require(SLAB_PATH .. '.Internal.UI.ListBox')
local Messages = require(SLAB_PATH .. '.Internal.Core.Messages')
local Mouse = require(SLAB_PATH .. '.Internal.Input.Mouse')
local Menu = require(SLAB_PATH .. '.Internal.UI.Menu')
local MenuState = require(SLAB_PATH .. '.Internal.UI.MenuState')
local MenuBar = require(SLAB_PATH .. '.Internal.UI.MenuBar')
local Region = require(SLAB_PATH .. '.Internal.UI.Region')
local Separator = require(SLAB_PATH .. '.Internal.UI.Separator')
local Shape = require(SLAB_PATH .. '.Internal.UI.Shape')
local Stats = require(SLAB_PATH .. '.Internal.Core.Stats')
local Style = require(SLAB_PATH .. '.Style')
local Text = require(SLAB_PATH .. '.Internal.UI.Text')
local Tree = require(SLAB_PATH .. '.Internal.UI.Tree')
local Utility = require(SLAB_PATH .. '.Internal.Core.Utility')
local Window = require(SLAB_PATH .. '.Internal.UI.Window')
--[[
Slab
Slab is an immediate mode GUI toolkit for the Love 2D framework. This library is designed to
allow users to easily add this library to their existing Love 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 Love 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.
Supported Version: 11.3.0
API:
Initialize
GetVersion
GetLoveVersion
Update
Draw
SetINIStatePath
GetINIStatePath
SetVerbose
GetMessages
Style:
GetStyle
PushFont
PopFont
Window:
BeginWindow
EndWindow
GetWindowPosition
GetWindowSize
GetWindowContentSize
GetWindowActiveSize
IsWindowAppearing
PushID
PopID
Menu:
BeginMainMenuBar
EndMainMenuBar
BeginMenuBar
EndMenuBar
BeginMenu
EndMenu
BeginContextMenuItem
BeginContextMenuWindow
EndContextMenu
MenuItem
MenuItemChecked
Separator
Button
RadioButton
Text
TextSelectable
Textf
GetTextSize
GetTextWidth
GetTextHeight
CheckBox
Input
InputNumberDrag
InputNumberSlider
GetInputText
GetInputNumber
GetInputCursorPos
IsInputFocused
IsAnyInputFocused
SetInputFocus
SetInputCursorPos
SetInputCursorPosLine
BeginTree
EndTree
BeginComboBox
EndComboBox
Image
Cursor:
SameLine
NewLine
SetCursorPos
GetCursorPos
Indent
Unindent
Properties
ListBox:
BeginListBox
EndListBox
BeginListBoxItem
IsListBoxItemClicked
EndListBoxItem
Dialog:
OpenDialog
BeginDialog
EndDialog
CloseDialog
MessageBox
FileDialog
ColorPicker
Mouse:
IsMouseDown
IsMouseClicked
IsMouseReleased
IsMouseDoubleClicked
IsMouseDragging
GetMousePosition
GetMousePositionWindow
GetMouseDelta
SetCustomMouseCursor
ClearCustomMouseCursor
Control:
IsControlHovered
IsControlClicked
GetControlSize
IsVoidHovered
IsVoidClicked
Keyboard:
IsKeyDown
IsKeyPressed
IsKeyReleased
Shape:
Rectangle
Circle
Triangle
Line
Curve
GetCurveControlPointCount
GetCurveControlPoint
EvaluateCurve
EvaluateCurveMouse
Polygon
Stats:
BeginStat
EndStat
EnableStats
IsStatsEnabled
FlushStats
Layout:
BeginLayout
EndLayout
SetLayoutColumn
GetLayoutSize
Scroll:
SetScrollSpeed
GetScrollSpeed
Shader:
PushShader
PopShader
Dock:
EnableDocks
DisableDocks
SetDockOptions
--]]
local Slab = {}
-- Slab version numbers.
local Version_Major = 0
local Version_Minor = 9
local Version_Revision = 0
local FrameStatHandle = nil
-- The path to save the UI state to a file. This will default to the save directory.
local INIStatePath = "Slab.ini"
local IsDefault = true
local QuitFn = nil
local Verbose = false
local Initialized = false
local DontInterceptEventHandlers = false
local ModifyCursor = true
local function LoadState()
if INIStatePath == nil then return end
local Result, Error = Config.LoadFile(INIStatePath, IsDefault)
if Result ~= nil then
Dock.Load(Result)
Tree.Load(Result)
Window.Load(Result)
end
if Verbose then
print("Load INI file:", INIStatePath, "Error:", Error)
end
end
local function SaveState()
if INIStatePath == nil then return end
local Table = {}
Dock.Save(Table)
Tree.Save(Table)
Window.Save(Table)
local Result, Error = Config.Save(INIStatePath, Table, IsDefault)
if Verbose then
print("Save INI file:", INIStatePath, "Error:", Error)
end
end
local function TextInput(Ch)
Input.Text(Ch)
if (not DontInterceptEventHandlers) and love.textinput ~= nil then
love.textinput(Ch)
end
end
local function WheelMoved(X, Y)
Window.WheelMoved(X, Y)
if (not DontInterceptEventHandlers) and love.wheelmoved ~= nil then
love.wheelmoved(X, Y)
end
end
local function OnQuit()
SaveState()
if QuitFn ~= nil then
QuitFn()
end
end
--[[
Event forwarding
--]]
Slab.OnTextInput = TextInput;
Slab.OnWheelMoved = WheelMoved;
Slab.OnQuit = OnQuit;
Slab.OnKeyPressed = Keyboard.OnKeyPressed;
Slab.OnKeyReleased = Keyboard.OnKeyReleased;
Slab.OnMouseMoved = Mouse.OnMouseMoved
Slab.OnMousePressed = Mouse.OnMousePressed;
Slab.OnMouseReleased = Mouse.OnMouseReleased;
--[[
Initialize
Initializes Slab and hooks into the required events. This function should be called in love.load.
args: [Table] The list of parameters passed in by the user on the command-line. This should be passed in from
love.load function. Below is a list of arguments available to modify Slab:
NoMessages: [String] Disables the messaging system that warns developers of any changes in the API.
NoDocks: [String] Disables all docks.
NoCursor: [String] Disables modifying the cursor
Return: None.
--]]
function Slab.Initialize(args, dontInterceptEventHandlers)
if Initialized then
return
end
DontInterceptEventHandlers = dontInterceptEventHandlers
Style.API.Initialize()
args = args or {}
if type(args) == 'table' then
for I, V in ipairs(args) do
if string.lower(V) == 'nomessages' then
Messages.SetEnabled(false)
elseif string.lower(V) == 'nodocks' then
Slab.DisableDocks({'Left', 'Right', 'Bottom'})
elseif string.lower(V) == 'nocursor' then
ModifyCursor = false
end
end
end
if not dontInterceptEventHandlers then
love.handlers['textinput'] = TextInput
love.handlers['wheelmoved'] = WheelMoved
-- In Love 11.3, overriding love.handlers['quit'] doesn't seem to affect the callback during shutdown.
-- Storing and overriding love.quit manually will properly call Slab's callback. This function will call
-- the stored function once Slab is finished with its process.
QuitFn = love.quit
love.quit = OnQuit
end
Keyboard.Initialize(args, dontInterceptEventHandlers)
Mouse.Initialize(args, dontInterceptEventHandlers)
LoadState()
Initialized = true
end
--[[
GetVersion
Retrieves the current version of Slab being used as a string.
Return: [String] String of the current Slab version.
--]]
function Slab.GetVersion()
return string.format("%d.%d.%d", Version_Major, Version_Minor, Version_Revision)
end
--[[
GetLoveVersion
Retrieves the current version of Love being used as a string.
Return: [String] String of the current Love version.
--]]
function Slab.GetLoveVersion()
local Major, Minor, Revision, Codename = love.getVersion()
return string.format("%d.%d.%d - %s", Major, Minor, Revision, Codename)
end
--[[
Update
Updates the input state and states of various widgets. This function must be called every frame.
This should be called before any Slab calls are made to ensure proper responses to Input are made.
dt: [Number] The delta time for the frame. This should be passed in from love.update.
Return: None.
--]]
function Slab.Update(dt)
Stats.Reset(false)
FrameStatHandle = Stats.Begin('Frame', 'Slab')
local StatHandle = Stats.Begin('Update', 'Slab')
Mouse.Update()
Keyboard.Update()
Input.Update(dt)
DrawCommands.Reset()
Window.Reset()
LayoutManager.Validate()
if MenuState.IsOpened then
MenuState.WasOpened = MenuState.IsOpened
if Mouse.IsClicked(1) then
MenuState.RequestClose = true
end
end
Stats.End(StatHandle)
end
--[[
Draw
This function will execute all buffered draw calls from the various Slab calls made prior. This
function should be called from love.draw and should be called at the very to ensure Slab is rendered
above the user's workspace.
Return: None.
--]]
function Slab.Draw()
if Stats.IsEnabled() then
PrevStatsData = love.graphics.getStats(PrevStatsData)
end
local StatHandle = Stats.Begin('Draw', 'Slab')
Window.Validate()
local MovingInstance = Window.GetMovingInstance()
if MovingInstance ~= nil then
Dock.DrawOverlay()
Dock.SetPendingWindow(MovingInstance)
else
Dock.Commit()
end
if MenuState.RequestClose then
Menu.Close()
MenuBar.Clear()
end
if ModifyCursor then
Mouse.Draw()
end
if Mouse.IsReleased(1) then
Button.ClearClicked()
end
love.graphics.setColor(1, 1, 1, 1)
love.graphics.push()
love.graphics.origin()
DrawCommands.Execute()
love.graphics.pop()
love.graphics.setColor(1, 1, 1, 1)
Stats.End(StatHandle)
-- Only call end if 'Update' was called and a valid handle was retrieved. This can happen for developers using a custom
-- run function with a fixed update.
if FrameStatHandle ~= nil then
Stats.End(FrameStatHandle)
FrameStatHandle = nil
end
if Stats.IsEnabled() then
StatsData = love.graphics.getStats(StatsData)
for k, v in pairs(StatsData) do
StatsData[k] = v - PrevStatsData[k]
end
end
end
--[[
SetINIStatePath
Sets the INI path to save the UI state. If nil, Slab will not save the state to disk.
Return: None.
--]]
function Slab.SetINIStatePath(Path)
INIStatePath = Path
IsDefault = false
end
--[[
GetINIStatePath
Gets the INI path to save the UI state. This value can be nil.
Return: [String] The path on disk the UI state will be saved to.
--]]
function Slab.GetINIStatePath()
return INIStatePath
end
--[[
SetVerbose
Enable/Disables internal Slab logging. Could be useful for diagnosing problems that occur inside of Slab.
IsVerbose: [Boolean] Flag to enable/disable verbose logging.
Return: None.
--]]
function Slab.SetVerbose(IsVerbose)
Verbose = (IsVerbose == nil or type(IsVerbose) ~= 'boolean') and false or IsVerbose
end
--[[
GetMessages
Retrieves a list of existing messages that has been captured by Slab.
Return: [Table] List of messages that have been broadcasted from Slab.
--]]
function Slab.GetMessages()
return Messages.Get()
end
--[[
GetStyle
Retrieve the style table associated with the current instance of Slab. This will allow the user to add custom styling
to their controls.
Return: [Table] The style table.
--]]
function Slab.GetStyle()
return Style
end
--[[
SetScale
Sets the rendering scale for the Slab context.
scaleFactor: [number] The scale factor to use
Return: None.
--]]
function Slab.SetScale(scaleFactor)
Scale.SetScale(scaleFactor)
end
--[[
GetScale
Retrieve the scale of the current Slab context.
Return: [number] The current scale.
--]]
function Slab.GetScale()
return Scale.GetScale()
end
--[[
PushFont
Pushes a Love font object onto the font stack. All text rendering will use this font until PopFont is called.
Font: [Object] The Love font object to use.
Return: None.
--]]
function Slab.PushFont(Font)
Style.API.PushFont(Font)
end
--[[
PopFont
Pops the last font from the stack.
Return: None.
--]]
function Slab.PopFont()
Style.API.PopFont()
end
--[[
BeginWindow
This function begins the process of drawing widgets to a window. This function must be followed up with
an EndWindow call to ensure proper behavior of drawing windows.
Id: [String] A unique string identifying this window in the project.
Options: [Table] List of options that control how this window will behave.
X: [Number] The X position to start rendering the window at.
Y: [Number] The Y position to start rendering the window at.
W: [Number] The starting width of the window.
H: [Number] The starting height of the window.
ContentW: [Number] The starting width of the content contained within this window.
ContentH: [Number] The starting height of the content contained within this window.
BgColor: [Table] The background color value for this window. Will use the default style WindowBackgroundColor if this is empty.
Title: [String] The title to display for this window. If emtpy, no title bar will be rendered and the window will not be movable.
TitleH: [Number] The height of the title bar. By default, this will be the height of the current font set in the style. If no title is
set, this is ignored.
TitleAlignX: [String] Horizontal alignment of the title. The available options are 'left', 'center', and 'right'. The default is 'center'.
TitleAlignY: [String] Vertical alignment of the title. The available options are 'top', 'center', and 'bottom'. The default is 'center'.
AllowMove: [Boolean] Controls whether the window is movable within the title bar area. The default value is true.
AllowResize: [Boolean] Controls whether the window is resizable. The default value is true. AutoSizeWindow must be false for this to work.
AllowFocus: [Boolean] Controls whether the window can be focused. The default value is true.
Border: [Number] The value which controls how much empty space should be left between all sides of the window from the content.
The default value is 4.0
NoOutline: [Boolean] Controls whether an outline should not be rendered. The default value is false.
IsMenuBar: [Boolean] Controls whether if this window is a menu bar or not. This flag should be ignored and is used by the menu bar
system. The default value is false.
AutoSizeWindow: [Boolean] Automatically updates the window size to match the content size. The default value is true.
AutoSizeWindowW: [Boolean] Automatically update the window width to match the content size. This value is taken from AutoSizeWindow by default.
AutoSizeWindowH: [Boolean] Automatically update the window height to match the content size. This value is taken from AutoSizeWindow by default.
AutoSizeContent: [Boolean] The content size of the window is automatically updated with each new widget. The default value is true.
Layer: [String] The layer to which to draw this window. This is used internally and should be ignored by the user.
ResetPosition: [Boolean] Determines if the window should reset any delta changes to its position.
ResetSize: [Boolean] Determines if the window should reset any delta changes to its size.
ResetContent: [Boolean] Determines if the window should reset any delta changes to its content size.
ResetLayout: [Boolean] Will reset the position, size, and content. Short hand for the above 3 flags.
SizerFilter: [Table] Specifies what sizers are enabled for the window. If nothing is specified, all sizers are available. The values can
be: NW, NE, SW, SE, N, S, E, W
CanObstruct: [Boolean] Sets whether this window is considered for obstruction of other windows and their controls. The default value is true.
Rounding: [Number] Amount of rounding to apply to the corners of the window.
IsOpen: [Boolean] Determines if the window is open. If this value exists within the options, a close button will appear in
the corner of the window and is updated when this button is pressed to reflect the new open state of this window.
NoSavedSettings: [Boolean] Flag to disable saving this window's settings to the state INI file.
ConstrainPosition: [Boolean] Flag to constrain the position of the window to the bounds of the viewport.
ShowMinimize: [Boolean] Flag to show a minimize button in the title bar of the window. Default is `true`.
ShowScrollbarX: [Boolean] Flag to show the horizontal scrollbar regardless of the window and content internal state. Default is `false`
ShowScrollbarY: [Boolean] Flag to show the vertical scrollbar regardless of the window and content internal state. Default is `false`
Return: [Boolean] The open state of this window. Useful for simplifying API calls by storing the result in a flag instead of a table.
EndWindow must still be called regardless of the result for this value.
--]]
function Slab.BeginWindow(Id, Options)
return Window.Begin(Id, Options)
end
--[[
EndWindow
This function must be called after a BeginWindow and associated widget calls. If the user fails to call this, an assertion will be thrown
to alert the user.
Return: None.
--]]
function Slab.EndWindow()
Window.End()
end
--[[
GetWindowPosition
Retrieves the active window's position.
Return: [Number], [Number] The X and Y position of the active window.
--]]
function Slab.GetWindowPosition()
return Window.GetPosition()
end
--[[
GetWindowSize
Retrieves the active window's size.
Return: [Number], [Number] The width and height of the active window.
--]]
function Slab.GetWindowSize()
return Window.GetSize()
end
--[[
GetWindowContentSize
Retrieves the active window's content size.
Return: [Number], [Number] The width and height of the active window content.
--]]
function Slab.GetWindowContentSize()
return Window.GetContentSize()
end
--[[
GetWindowActiveSize
Retrieves the active window's active size minus the borders.
Return: [Number], [Number] The width and height of the window's active bounds.
--]]
function Slab.GetWindowActiveSize()
return Window.GetBorderlessSize()
end
--[[
IsWindowAppearing
Is the current window appearing this frame. This will return true if BeginWindow has
not been called for a window over 2 or more frames.
Return: [Boolean] True if the window is appearing this frame. False otherwise.
--]]
function Slab.IsWindowAppearing()
return Window.IsAppearing()
end
--[[
PushID
Pushes a custom ID onto a stack. This allows developers to differentiate between similar controls such as
text controls.
ID: [String] The custom ID to add.
Return: None.
--]]
function Slab.PushID(ID)
assert(type(ID) == 'string', "'ID' parameter must be a string value.")
Window.PushID(ID)
end
--[[
PopID
Pops the last custom ID from the stack.
Return: None.
--]]
function Slab.PopID()
Window.PopID()
end
--[[
BeginMainMenuBar
This function begins the process for setting up the main menu bar. This should be called outside of any BeginWindow/EndWindow calls.
The user should only call EndMainMenuBar if this function returns true. Use BeginMenu/EndMenu calls to add menu items on the main menu bar.
Example:
if Slab.BeginMainMenuBar() then
if Slab.BeginMenu("File") then
if Slab.MenuItem("Quit") then
love.event.quit()
end
Slab.EndMenu()
end
Slab.EndMainMenuBar()
end
Return: [Boolean] Returns true if the main menu bar process has started.
--]]
function Slab.BeginMainMenuBar()
local X,Y = 0.0, 0.0
if Utility.IsMobile() then
X, Y = love.window.getSafeArea()
end
Cursor.SetPosition(X, Y)
return Slab.BeginMenuBar(true)
end
--[[
EndMainMenuBar
This function should be called if BeginMainMenuBar returns true.
Return: None.
--]]
function Slab.EndMainMenuBar()
Slab.EndMenuBar()
end
--[[
BeginMenuBar
This function begins the process of rendering a menu bar for a window. This should only be called within a BeginWindow/EndWindow context.
IsMainMenuBar: [Boolean] Is this menu bar for the main viewport. Used internally. Should be ignored for all other calls.
Return: [Boolean] Returns true if the menu bar process has started.
--]]
function Slab.BeginMenuBar(IsMainMenuBar)
return MenuBar.Begin(IsMainMenuBar)
end
--[[
EndMenuBar
This function should be called if BeginMenuBar returns true.
Return: None.
--]]
function Slab.EndMenuBar()
MenuBar.End()
end
--[[
BeginMenu
Adds a menu item that when the user hovers over, opens up an additional context menu. When used within a menu bar, BeginMenu calls
will be added to the bar. Within a context menu, the menu item will be added within the context menu with an additional arrow to notify
the user more options are available. If this function returns true, the user must call EndMenu.
Label: [String] The label to display for this menu.
Options: [Table] List of options that control how this menu behaves.
Enabled: [Boolean] Determines if this menu is enabled. This value is true by default. Disabled items are displayed but
cannot be interacted with.
Return: [Boolean] Returns true if the menu item is being hovered.
--]]
function Slab.BeginMenu(Label, Options)
return Menu.BeginMenu(Label, Options)
end
--[[
EndMenu
Finishes up a BeginMenu. This function must be called if BeginMenu returns true.
Return: None.
--]]
function Slab.EndMenu()
Menu.EndMenu()
end
--[[
BeginContextMenuItem
Opens up a context menu based on if the user right clicks on the last item. This function should be placed immediately after an item
call to open up a context menu for that specific item. If this function returns true, EndContextMenu must be called.
Example:
if Slab.Button("Button!") then
-- Perform logic here when button is clicked
end
-- This will only return true if the previous button is hot and the user right-clicks.
if Slab.BeginContextMenuItem() then
Slab.MenuItem("Button Item 1")
Slab.MenuItem("Button Item 2")
Slab.EndContextMenu()
end
Button: [Number] The mouse button to use for opening up this context menu.
Return: [Boolean] Returns true if the user right clicks on the previous item call. EndContextMenu must be called in order for
this to function properly.
--]]
function Slab.BeginContextMenuItem(Button)
return Menu.BeginContextMenu({IsItem = true, Button = Button})
end
--[[
BeginContextMenuWindow
Opens up a context menu based on if the user right clicks anywhere within the window. It is recommended to place this function at the end
of a window's widget calls so that Slab can catch any BeginContextMenuItem calls before this call. If this function returns true,
EndContextMenu must be called.
Button: [Number] The mouse button to use for opening up this context menu.
Return: [Boolean] Returns true if the user right clicks anywhere within the window. EndContextMenu must be called in order for this
to function properly.
--]]
function Slab.BeginContextMenuWindow(Button)
return Menu.BeginContextMenu({IsWindow = true, Button = Button})
end
--[[
EndContextMenu
Finishes up any BeginContextMenuItem/BeginContextMenuWindow if they return true.
Return: None.
--]]
function Slab.EndContextMenu()
Menu.EndContextMenu()
end
--[[
MenuItem
Adds a menu item to a given context menu.
Label: [String] The label to display to the user.
Options: [Table] List of options that control how this menu behaves.
Enabled: [Boolean] Determines if this menu is enabled. This value is true by default. Disabled items are displayed but
cannot be interacted with.
Hint: [String] Show an input hint to the right of the menu item
Return: [Boolean] Returns true if the user clicks on this menu item.
--]]
function Slab.MenuItem(Label, Options)
return Menu.MenuItem(Label, Options)
end
--[[
MenuItemChecked
Adds a menu item to a given context menu. If IsChecked is true, then a check mark will be rendered next to the
label.
Example:
local Checked = false
if Slab.MenuItemChecked("Menu Item", Checked)
Checked = not Checked
end
Label: [String] The label to display to the user.
IsChecked: [Boolean] Determines if a check mark should be rendered next to the label.
Options: [Table] List of options that control how this menu behaves.
Enabled: [Boolean] Determines if this menu is enabled. This value is true by default. Disabled items are displayed but
cannot be interacted with.
Return: [Boolean] Returns true if the user clicks on this menu item.
--]]
function Slab.MenuItemChecked(Label, IsChecked, Options)
return Menu.MenuItemChecked(Label, IsChecked, Options)
end
--[[
Separator
This functions renders a separator line in the window.
Option: [Table] List of options for how this separator will be drawn.
IncludeBorders: [Boolean] Whether to extend the separator to include the window borders. This is false by default.
H: [Number] The height of the separator. This doesn't change the line thickness, rather, specifies the cursor advancement
in the Y direction.
Thickness: [Number] The thickness of the line rendered. The default value is 1.0.
Return: None.
--]]
function Slab.Separator(Options)
Separator.Begin(Options)
end
--[[
Button
Adds a button to the active window.
Label: [String] The label to display on the button.
Options: [Table] List of options for how this button will behave.
Tooltip: [String] The tooltip to display when the user hovers over this button.
Rounding: [Number] Amount of rounding to apply to the corners of the button.
Invisible: [Boolean] Don't render the button, but keep the behavior.
W: [Number] Override the width of the button.
H: [Number] Override the height of the button.
Disabled: [Boolean] If true, the button is not interactable by the user.
Image: [Table] A table of options used to draw an image instead of a text label. Refer to the 'Image' documentation for a list
of available options.
Color: [Table]: The background color of the button when idle. The default value is the ButtonColor property in the Style's table.
HoverColor: [Table]: The background color of the button when a mouse is hovering the control. The default value is the ButtonHoveredColor property
in the Style's table.
PressColor: [Table]: The background color of the button when the button is pressed but not released. The default value is the ButtonPressedColor
property in the Style's table.
PadX: [Number] Amount of additional horizontal space the background will expand to from the center. The default value is 20.
PadY: [Number] Amount of additional vertical space the background will expand to from the center. The default value is 5.
VLines: [Number] Number of lines in a multiline button text. The default value is 1.
Return: [Boolean] Returns true if the user clicks on this button.
--]]
function Slab.Button(Label, Options)
return Button.Begin(Label, Options)
end
--[[
RadioButton
Adds a radio button entry to the active window. The grouping of radio buttons is determined by the user. An Index can
be applied to the given radio button and a SelectedIndex can be passed in to determine if this specific radio button
is the selected one.
Label: [String] The label to display next to the button.
Options: [Table] List of options for how this radio button will behave.
Index: [Number] The index of this radio button. Will be 0 by default and not selectable. Assign an index to group the button.
SelectedIndex: [Number] The index of the radio button that is selected. If this equals the Index field, then this radio button