API.lua 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996
  1. --[[
  2. MIT License
  3. Copyright (c) 2019 Mitchell Davis <coding.jackalope@gmail.com>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. --]]
  20. if SLAB_PATH == nil then
  21. SLAB_PATH = (...):match("(.-)[^%.]+$")
  22. end
  23. local Button = require(SLAB_PATH .. '.Internal.UI.Button')
  24. local CheckBox = require(SLAB_PATH .. '.Internal.UI.CheckBox')
  25. local ColorPicker = require(SLAB_PATH .. '.Internal.UI.ColorPicker')
  26. local ComboBox = require(SLAB_PATH .. '.Internal.UI.ComboBox')
  27. local Cursor = require(SLAB_PATH .. '.Internal.Core.Cursor')
  28. local Dialog = require(SLAB_PATH .. '.Internal.UI.Dialog')
  29. local Dock = require(SLAB_PATH .. '.Internal.UI.Dock')
  30. local DrawCommands = require(SLAB_PATH .. '.Internal.Core.DrawCommands')
  31. local Image = require(SLAB_PATH .. '.Internal.UI.Image')
  32. local Input = require(SLAB_PATH .. '.Internal.UI.Input')
  33. local Keyboard = require(SLAB_PATH .. '.Internal.Input.Keyboard')
  34. local LayoutManager = require(SLAB_PATH .. '.Internal.UI.LayoutManager')
  35. local ListBox = require(SLAB_PATH .. '.Internal.UI.ListBox')
  36. local Mouse = require(SLAB_PATH .. '.Internal.Input.Mouse')
  37. local Menu = require(SLAB_PATH .. '.Internal.UI.Menu')
  38. local MenuState = require(SLAB_PATH .. '.Internal.UI.MenuState')
  39. local MenuBar = require(SLAB_PATH .. '.Internal.UI.MenuBar')
  40. local Region = require(SLAB_PATH .. '.Internal.UI.Region')
  41. local Separator = require(SLAB_PATH .. '.Internal.UI.Separator')
  42. local Shape = require(SLAB_PATH .. '.Internal.UI.Shape')
  43. local Stats = require(SLAB_PATH .. '.Internal.Core.Stats')
  44. local Style = require(SLAB_PATH .. '.Style')
  45. local Tab = require(SLAB_PATH .. '.Internal.UI.Tab')
  46. local Text = require(SLAB_PATH .. '.Internal.UI.Text')
  47. local Tree = require(SLAB_PATH .. '.Internal.UI.Tree')
  48. local Window = require(SLAB_PATH .. '.Internal.UI.Window')
  49. --[[
  50. Slab
  51. Slab is an immediate mode GUI toolkit for the Love 2D framework. This library is designed to
  52. allow users to easily add this library to their existing Love 2D projects and quickly create
  53. tools to enable them to iterate on their ideas quickly. The user should be able to utilize this
  54. library with minimal integration steps and is completely written in Lua and utilizes
  55. the Love 2D API. No compiled binaries are required and the user will have access to the source
  56. so that they may make adjustments that meet the needs of their own projects and tools. Refer
  57. to main.lua and SlabTest.lua for example usage of this library.
  58. Supported Version: 11.2.0
  59. API:
  60. Initialize
  61. GetVersion
  62. GetLoveVersion
  63. Update
  64. Draw
  65. Style:
  66. GetStyle
  67. PushFont
  68. PopFont
  69. Window:
  70. BeginWindow
  71. EndWindow
  72. GetWindowPosition
  73. GetWindowSize
  74. GetWindowContentSize
  75. GetWindowActiveSize
  76. Menu:
  77. BeginMainMenuBar
  78. EndMainMenuBar
  79. BeginMenuBar
  80. EndMenuBar
  81. BeginMenu
  82. EndMenu
  83. BeginContextMenuItem
  84. BeginContextMenuWindow
  85. EndContextMenu
  86. MenuItem
  87. MenuItemChecked
  88. Separator
  89. Button
  90. RadioButton
  91. Text
  92. TextSelectable
  93. Textf
  94. GetTextSize
  95. GetTextWidth
  96. GetTextHeight
  97. CheckBox
  98. Input
  99. GetInputText
  100. GetInputNumber
  101. GetInputCursorPos
  102. IsInputFocused
  103. SetInputFocus
  104. SetInputCursorPos
  105. SetInputCursorPosLine
  106. BeginTree
  107. EndTree
  108. BeginComboBox
  109. EndComboBox
  110. Image
  111. Cursor:
  112. SameLine
  113. NewLine
  114. SetCursorPos
  115. GetCursorPos
  116. Properties
  117. ListBox:
  118. BeginListBox
  119. EndListBox
  120. BeginListBoxItem
  121. IsListBoxItemClicked
  122. EndListBoxItem
  123. Dialog:
  124. OpenDialog
  125. BeginDialog
  126. EndDialog
  127. CloseDialog
  128. MessageBox
  129. FileDialog
  130. Mouse:
  131. IsMouseDown
  132. IsMouseClicked
  133. IsMouseReleased
  134. IsMouseDoubleClicked
  135. IsMouseDragging
  136. GetMousePosition
  137. GetMousePositionWindow
  138. GetMouseDelta
  139. Control:
  140. IsControlHovered
  141. IsControlClicked
  142. GetControlSize
  143. IsVoidHovered
  144. IsVoidClicked
  145. Keyboard:
  146. IsKeyDown
  147. IsKeyPressed
  148. IsKeyReleased
  149. Shape:
  150. Rectangle
  151. Circle
  152. Triangle
  153. Line
  154. Curve
  155. GetCurveControlPointCount
  156. GetCurveControlPoint
  157. EvaluateCurve
  158. EvaluateCurveMouse
  159. Polygon
  160. Stats:
  161. BeginStat
  162. EndStat
  163. EnableStats
  164. IsStatsEnabled
  165. FlushStats
  166. Layout:
  167. BeginLayout
  168. EndLayout
  169. SetLayoutColumn
  170. GetLayoutSize
  171. --]]
  172. local Slab = {}
  173. -- Slab version numbers.
  174. local Version_Major = 0
  175. local Version_Minor = 7
  176. local Version_Revision = 0
  177. local FrameNumber = 0
  178. local FrameStatHandle = nil
  179. local PendingDockWindow = nil
  180. local function TextInput(Ch)
  181. Input.Text(Ch)
  182. if love.textinput ~= nil then
  183. love.textinput(Ch)
  184. end
  185. end
  186. local function WheelMoved(X, Y)
  187. Window.WheelMoved(X, Y)
  188. if love.wheelmoved ~= nil then
  189. love.wheelmoved(X, Y)
  190. end
  191. end
  192. --[[
  193. Initialize
  194. Initializes Slab and hooks into the required events. This function should be called in love.load.
  195. args: [Table] The list of parameters passed in by the user on the command-line. This should be passed in from
  196. love.load function.
  197. Return: None.
  198. --]]
  199. function Slab.Initialize(args)
  200. Style.API.Initialize()
  201. love.handlers['textinput'] = TextInput
  202. love.handlers['wheelmoved'] = WheelMoved
  203. end
  204. --[[
  205. GetVersion
  206. Retrieves the current version of Slab being used as a string.
  207. Return: [String] String of the current Slab version.
  208. --]]
  209. function Slab.GetVersion()
  210. return string.format("%d.%d.%d", Version_Major, Version_Minor, Version_Revision)
  211. end
  212. --[[
  213. GetLoveVersion
  214. Retrieves the current version of Love being used as a string.
  215. Return: [String] String of the current Love version.
  216. --]]
  217. function Slab.GetLoveVersion()
  218. local Major, Minor, Revision, Codename = love.getVersion()
  219. return string.format("%d.%d.%d - %s", Major, Minor, Revision, Codename)
  220. end
  221. --[[
  222. Update
  223. Updates the input state and states of various widgets. This function must be called every frame.
  224. This should be called before any Slab calls are made to ensure proper responses to Input are made.
  225. dt: [Number] The delta time for the frame. This should be passed in from love.update.
  226. Return: None.
  227. --]]
  228. function Slab.Update(dt)
  229. FrameNumber = FrameNumber + 1
  230. Stats.Reset()
  231. FrameStatHandle = Stats.Begin('Frame', 'Slab')
  232. local StatHandle = Stats.Begin('Update', 'Slab')
  233. Mouse.Update()
  234. Keyboard.Update()
  235. Input.Update(dt)
  236. DrawCommands.Reset()
  237. Window.Reset()
  238. Window.SetFrameNumber(FrameNumber)
  239. LayoutManager.Validate()
  240. if MenuState.IsOpened then
  241. MenuState.WasOpened = MenuState.IsOpened
  242. if Mouse.IsClicked(1) then
  243. MenuState.RequestClose = true
  244. end
  245. end
  246. Stats.End(StatHandle)
  247. end
  248. --[[
  249. Draw
  250. This function will execute all buffered draw calls from the various Slab calls made prior. This
  251. function should be called from love.draw and should be called at the very to ensure Slab is rendered
  252. above the user's workspace.
  253. Return: None.
  254. --]]
  255. function Slab.Draw()
  256. local StatHandle = Stats.Begin('Draw', 'Slab')
  257. Window.Validate()
  258. Tab.Validate()
  259. local MovingInstance = Window.GetMovingInstance()
  260. if MovingInstance ~= nil then
  261. Dock.DrawOverlay()
  262. PendingDockWindow = MovingInstance
  263. else
  264. Dock.Commit(PendingDockWindow)
  265. PendingDockWindow = nil
  266. end
  267. if MenuState.RequestClose then
  268. Menu.Close()
  269. MenuBar.Clear()
  270. end
  271. Mouse.UpdateCursor()
  272. if Mouse.IsReleased(1) then
  273. Button.ClearClicked()
  274. end
  275. DrawCommands.Execute()
  276. Stats.End(StatHandle)
  277. Stats.End(FrameStatHandle)
  278. end
  279. --[[
  280. GetStyle
  281. Retrieve the style table associated with the current instance of Slab. This will allow the user to add custom styling
  282. to their controls.
  283. Return: [Table] The style table.
  284. --]]
  285. function Slab.GetStyle()
  286. return Style
  287. end
  288. --[[
  289. PushFont
  290. Pushes a Love font object onto the font stack. All text rendering will use this font until PopFont is called.
  291. Font: [Object] The Love font object to use.
  292. Return: None.
  293. --]]
  294. function Slab.PushFont(Font)
  295. Style.API.PushFont(Font)
  296. end
  297. --[[
  298. PopFont
  299. Pops the last font from the stack.
  300. Return: None.
  301. --]]
  302. function Slab.PopFont()
  303. Style.API.PopFont()
  304. end
  305. --[[
  306. BeginWindow
  307. This function begins the process of drawing widgets to a window. This function must be followed up with
  308. an EndWindow call to ensure proper behavior of drawing windows.
  309. Id: [String] A unique string identifying this window in the project.
  310. Options: [Table] List of options that control how this window will behave.
  311. X: [Number] The X position to start rendering the window at.
  312. Y: [Number] The Y position to start rendering the window at.
  313. W: [Number] The starting width of the window.
  314. H: [Number] The starting height of the window.
  315. ContentW: [Number] The starting width of the content contained within this window.
  316. ContentH: [Number] The starting height of the content contained within this window.
  317. BgColor: [Table] The background color value for this window. Will use the default style WindowBackgroundColor if this is empty.
  318. Title: [String] The title to display for this window. If emtpy, no title bar will be rendered and the window will not be movable.
  319. AllowMove: [Boolean] Controls whether the window is movable within the title bar area. The default value is true.
  320. AllowResize: [Boolean] Controls whether the window is resizable. The default value is true. AutoSizeWindow must be false for this to work.
  321. AllowFocus: [Boolean] Controls whether the window can be focused. The default value is true.
  322. Border: [Number] The value which controls how much empty space should be left between all sides of the window from the content.
  323. The default value is 4.0
  324. NoOutline: [Boolean] Controls whether an outline should not be rendered. The default value is false.
  325. 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
  326. system. The default value is false.
  327. AutoSizeWindow: [Boolean] Automatically updates the window size to match the content size. The default value is true.
  328. AutoSizeWindowW: [Boolean] Automatically update the window width to match the content size. This value is taken from AutoSizeWindow by default.
  329. AutoSizeWindowH: [Boolean] Automatically update the window height to match the content size. This value is taken from AutoSizeWindow by default.
  330. AutoSizeContent: [Boolean] The content size of the window is automatically updated with each new widget. The default value is true.
  331. Layer: [String] The layer to which to draw this window. This is used internally and should be ignored by the user.
  332. ResetPosition: [Boolean] Determines if the window should reset any delta changes to its position.
  333. ResetSize: [Boolean] Determines if the window should reset any delta changes to its size.
  334. ResetContent: [Boolean] Determines if the window should reset any delta changes to its content size.
  335. ResetLayout: [Boolean] Will reset the position, size, and content. Short hand for the above 3 flags.
  336. SizerFilter: [Table] Specifies what sizers are enabled for the window. If nothing is specified, all sizers are available. The values can
  337. be: NW, NE, SW, SE, N, S, E, W
  338. CanObstruct: [Boolean] Sets whether this window is considered for obstruction of other windows and their controls. The default value is true.
  339. Rounding: [Number] Amount of rounding to apply to the corners of the window.
  340. Return: None
  341. --]]
  342. function Slab.BeginWindow(Id, Options)
  343. Window.Begin(Id, Options)
  344. end
  345. --[[
  346. EndWindow
  347. This function must be called after a BeginWindow and associated widget calls. If the user fails to call this, an assertion will be thrown
  348. to alert the user.
  349. Return: None.
  350. --]]
  351. function Slab.EndWindow()
  352. Window.End()
  353. end
  354. --[[
  355. GetWindowPosition
  356. Retrieves the active window's position.
  357. IncludeTitle: [Boolean] Should the Y position include the title bar. If false, will use the Y position of the body.
  358. Return: [Number], [Number] The X and Y position of the active window.
  359. --]]
  360. function Slab.GetWindowPosition(IncludeTitle)
  361. return Window.GetPosition(IncludeTitle)
  362. end
  363. --[[
  364. GetWindowSize
  365. Retrieves the active window's size.
  366. Return: [Number], [Number] The width and height of the active window.
  367. --]]
  368. function Slab.GetWindowSize()
  369. return Window.GetSize()
  370. end
  371. --[[
  372. GetWindowContentSize
  373. Retrieves the active window's content size.
  374. Return: [Number], [Number] The width and height of the active window content.
  375. --]]
  376. function Slab.GetWindowContentSize()
  377. return Window.GetContentSize()
  378. end
  379. --[[
  380. GetWindowActiveSize
  381. Retrieves the active window's active size minus the borders.
  382. Return: [Number], [Number] The width and height of the window's active bounds.
  383. --]]
  384. function Slab.GetWindowActiveSize()
  385. return Window.GetBorderlessSize()
  386. end
  387. --[[
  388. BeginMainMenuBar
  389. This function begins the process for setting up the main menu bar. This should be called outside of any BeginWindow/EndWindow calls.
  390. The user should only call EndMainMenuBar if this function returns true. Use BeginMenu/EndMenu calls to add menu items on the main menu bar.
  391. Example:
  392. if Slab.BeginMainMenuBar() then
  393. if Slab.BeginMenu("File") then
  394. if Slab.MenuItem("Quit") then
  395. love.event.quit()
  396. end
  397. Slab.EndMenu()
  398. end
  399. Slab.EndMainMenuBar()
  400. end
  401. Return: [Boolean] Returns true if the main menu bar process has started.
  402. --]]
  403. function Slab.BeginMainMenuBar()
  404. Cursor.SetPosition(0.0, 0.0)
  405. return Slab.BeginMenuBar(true)
  406. end
  407. --[[
  408. EndMainMenuBar
  409. This function should be called if BeginMainMenuBar returns true.
  410. Return: None.
  411. --]]
  412. function Slab.EndMainMenuBar()
  413. Slab.EndMenuBar()
  414. end
  415. --[[
  416. BeginMenuBar
  417. This function begins the process of rendering a menu bar for a window. This should only be called within a BeginWindow/EndWindow context.
  418. IsMainMenuBar: [Boolean] Is this menu bar for the main viewport. Used internally. Should be ignored for all other calls.
  419. Return: [Boolean] Returns true if the menu bar process has started.
  420. --]]
  421. function Slab.BeginMenuBar(IsMainMenuBar)
  422. return MenuBar.Begin(IsMainMenuBar)
  423. end
  424. --[[
  425. EndMenuBar
  426. This function should be called if BeginMenuBar returns true.
  427. Return: None.
  428. --]]
  429. function Slab.EndMenuBar()
  430. MenuBar.End()
  431. end
  432. --[[
  433. BeginMenu
  434. Adds a menu item that when the user hovers over, opens up an additional context menu. When used within a menu bar, BeginMenu calls
  435. 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
  436. the user more options are available. If this function returns true, the user must call EndMenu.
  437. Label: [String] The label to display for this menu.
  438. Return: [Boolean] Returns true if the menu item is being hovered.
  439. --]]
  440. function Slab.BeginMenu(Label)
  441. return Menu.BeginMenu(Label)
  442. end
  443. --[[
  444. EndMenu
  445. Finishes up a BeginMenu. This function must be called if BeginMenu returns true.
  446. Return: None.
  447. --]]
  448. function Slab.EndMenu()
  449. Menu.EndMenu()
  450. end
  451. --[[
  452. BeginContextMenuItem
  453. 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
  454. call to open up a context menu for that specific item. If this function returns true, EndContextMenu must be called.
  455. Example:
  456. if Slab.Button("Button!") then
  457. -- Perform logic here when button is clicked
  458. end
  459. -- This will only return true if the previous button is hot and the user right-clicks.
  460. if Slab.BeginContextMenuItem() then
  461. Slab.MenuItem("Button Item 1")
  462. Slab.MenuItem("Button Item 2")
  463. Slab.EndContextMenu()
  464. end
  465. Return: [Boolean] Returns true if the user right clicks on the previous item call. EndContextMenu must be called in order for
  466. this to function properly.
  467. --]]
  468. function Slab.BeginContextMenuItem()
  469. return Menu.BeginContextMenu({IsItem = true})
  470. end
  471. --[[
  472. BeginContextMenuWindow
  473. 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
  474. of a window's widget calls so that Slab can catch any BeginContextMenuItem calls before this call. If this function returns true,
  475. EndContextMenu must be called.
  476. Return: [Boolean] Returns true if the user right clicks anywhere within the window. EndContextMenu must be called in order for this
  477. to function properly.
  478. --]]
  479. function Slab.BeginContextMenuWindow()
  480. return Menu.BeginContextMenu({IsWindow = true})
  481. end
  482. --[[
  483. EndContextMenu
  484. Finishes up any BeginContextMenuItem/BeginContextMenuWindow if they return true.
  485. Return: None.
  486. --]]
  487. function Slab.EndContextMenu()
  488. Menu.EndContextMenu()
  489. end
  490. --[[
  491. MenuItem
  492. Adds a menu item to a given context menu.
  493. Label: [String] The label to display to the user.
  494. Return: [Boolean] Returns true if the user clicks on this menu item.
  495. --]]
  496. function Slab.MenuItem(Label)
  497. return Menu.MenuItem(Label)
  498. end
  499. --[[
  500. MenuItemChecked
  501. Adds a menu item to a given context menu. If IsChecked is true, then a check mark will be rendered next to the
  502. label.
  503. Example:
  504. local Checked = false
  505. if Slab.MenuItemChecked("Menu Item", Checked)
  506. Checked = not Checked
  507. end
  508. Label: [String] The label to display to the user.
  509. IsChecked: [Boolean] Determines if a check mark should be rendered next to the label.
  510. Return: [Boolean] Returns true if the user clicks on this menu item.
  511. --]]
  512. function Slab.MenuItemChecked(Label, IsChecked)
  513. return Menu.MenuItemChecked(Label, IsChecked)
  514. end
  515. --[[
  516. Separator
  517. This functions renders a separator line in the window.
  518. Option: [Table] List of options for how this separator will be drawn.
  519. IncludeBorders: [Boolean] Whether to extend the separator to include the window borders. This is false by default.
  520. H: [Number] The height of the separator. This doesn't change the line thickness, rather, specifies the cursor advancement
  521. in the Y direction.
  522. Thickness: [Number] The thickness of the line rendered. The default value is 1.0.
  523. Return: None.
  524. --]]
  525. function Slab.Separator(Options)
  526. Separator.Begin(Options)
  527. end
  528. --[[
  529. Button
  530. Adds a button to the active window.
  531. Label: [String] The label to display on the button.
  532. Options: [Table] List of options for how this button will behave.
  533. Tooltip: [String] The tooltip to display when the user hovers over this button.
  534. Rounding: [Number] Amount of rounding to apply to the corners of the button.
  535. Invisible: [Boolean] Don't render the button, but keep the behavior.
  536. W: [Number] Override the width of the button.
  537. H: [Number] Override the height of the button.
  538. Disabled: [Boolean] If true, the button is not interactable by the user.
  539. Return: [Boolean] Returns true if the user clicks on this button.
  540. --]]
  541. function Slab.Button(Label, Options)
  542. return Button.Begin(Label, Options)
  543. end
  544. --[[
  545. RadioButton
  546. Adds a radio button entry to the active window. The grouping of radio buttons is determined by the user. An Index can
  547. be applied to the given radio button and a SelectedIndex can be passed in to determine if this specific radio button
  548. is the selected one.
  549. Label: [String] The label to display next to the button.
  550. Options: [Table] List of options for how this radio button will behave.
  551. Index: [Number] The index of this radio button. Will be 0 by default and not selectable. Assign an index to group the button.
  552. SelectedIndex: [Number] The index of the radio button that is selected. If this equals the Index field, then this radio button
  553. will be rendered as selected.
  554. Tooltip: [String] The tooltip to display when the user hovers over the button or label.
  555. Return: [Boolean] Returns true if the user clicks on this button.
  556. --]]
  557. function Slab.RadioButton(Label, Options)
  558. return Button.BeginRadio(Label, Options)
  559. end
  560. --[[
  561. Text
  562. Adds text to the active window.
  563. Label: [String] The string to be displayed in the window.
  564. Options: [Table] List of options for how this text is displayed.
  565. Color: [Table] The color to render the text.
  566. Pad: [Number] How far to pad the text from the left side of the current cursor position.
  567. IsSelectable: [Boolean] Whether this text is selectable using the text's Y position and the window X and width as the
  568. hot zone.
  569. IsSelectableTextOnly: [Boolean] Only available if IsSelectable is true. Will use the text width instead of the
  570. window width to determine the hot zone.
  571. IsSelected: [Boolean] Forces the hover background to be rendered.
  572. SelectOnHover: [Boolean] Returns true if the user is hovering over the hot zone of this text.
  573. HoverColor: [Table] The color to render the background if the IsSelected option is true.
  574. Return: [Boolean] Returns true if SelectOnHover option is set to true. False otherwise.
  575. --]]
  576. function Slab.Text(Label, Options)
  577. return Text.Begin(Label, Options)
  578. end
  579. --[[
  580. TextSelectable
  581. This function is a shortcut for SlabText with the IsSelectable option set to true.
  582. Label: [String] The string to be displayed in the window.
  583. Options: [Table] List of options for how this text is displayed.
  584. See Slab.Text for all options.
  585. Return: [Boolean] Returns true if user clicks on this text. False otherwise.
  586. --]]
  587. function Slab.TextSelectable(Label, Options)
  588. Options = Options == nil and {} or Options
  589. Options.IsSelectable = true
  590. return Slab.Text(Label, Options)
  591. end
  592. --[[
  593. Textf
  594. Adds formatted text to the active window. This text will wrap to fit within the contents of
  595. either the window or a user specified width.
  596. Label: [String] The text to be rendered.
  597. Options: [Table] List of options for how this text is displayed.
  598. Color: [Table] The color to render the text.
  599. W: [Number] The width to restrict the text to. If this option is not specified, then the window
  600. width is used.
  601. Align: [String] The alignment to use for this text. For more information, refer to the love documentation
  602. at https://love2d.org/wiki/AlignMode. Below are the available options:
  603. center: Align text center.
  604. left: Align text left.
  605. right: Align text right.
  606. justify: Align text both left and right.
  607. Return: None.
  608. --]]
  609. function Slab.Textf(Label, Options)
  610. Text.BeginFormatted(Label, Options)
  611. end
  612. --[[
  613. GetTextSize
  614. Retrieves the width and height of the given text. The result is based on the current font.
  615. Label: [String] The string to retrieve the size for.
  616. Return: [Number], [Number] The width and height of the given text.
  617. --]]
  618. function Slab.GetTextSize(Label)
  619. return Text.GetSize(Label)
  620. end
  621. --[[
  622. GetTextWidth
  623. Retrieves the width of the given text. The result is based on the current font.
  624. Label: [String] The string to retrieve the width for.
  625. Return: [Number] The width of the given text.
  626. --]]
  627. function Slab.GetTextWidth(Label)
  628. local W, H = Slab.GetTextSize(Label)
  629. return W
  630. end
  631. --[[
  632. GetTextHeight
  633. Retrieves the height of the current font.
  634. Return: [Number] The height of the current font.
  635. --]]
  636. function Slab.GetTextHeight()
  637. return Text.GetHeight()
  638. end
  639. --[[
  640. CheckBox
  641. Renders a check box with a label. The check box when enabled will render an 'X'.
  642. Enabled: [Boolean] Will render an 'X' within the box if true. Will be an empty box otherwise.
  643. Label: [String] The label to display after the check box.
  644. Options: [Table] List of options for how this check box will behave.
  645. Tooltip: [String] Text to be displayed if the user hovers over the check box.
  646. Id: [String] An optional Id that can be supplied by the user. By default, the Id will be the label.
  647. Rounding: [Number] Amount of rounding to apply to the corners of the check box.
  648. Size: [Number] The uniform size of the box. The default value is 16.
  649. Return: [Boolean] Returns true if the user clicks within the check box.
  650. --]]
  651. function Slab.CheckBox(Enabled, Label, Options)
  652. return CheckBox.Begin(Enabled, Label, Options)
  653. end
  654. --[[
  655. Input
  656. This function will render an input box for a user to input text in. This widget behaves like input boxes
  657. found in other applications. This function will only return true if it has focus and user has either input
  658. text or pressed the return key.
  659. Example:
  660. local Text = "Hello World"
  661. if Slab.Input('Example', {Text = Text}) then
  662. Text = Slab.GetInputText()
  663. end
  664. Id: [String] A string that uniquely identifies this Input within the context of the window.
  665. Options: [Table] List of options for how this Input will behave.
  666. Tooltip: [String] Text to be displayed if the user hovers over the Input box.
  667. ReturnOnText: [Boolean] Will cause this function to return true whenever the user has input
  668. a new character into the Input box. This is true by default.
  669. Text: [String] The text to be supplied to the input box. It is recommended to use this option
  670. when ReturnOnText is true.
  671. TextColor: [Table] The color to use for the text. The default color is the color used for text, but there is also
  672. a default multiline text color defined in the Style.
  673. BgColor: [Table] The background color for the input box.
  674. SelectColor: [Table] The color used when the user is selecting text within the input box.
  675. SelectOnFocus: [Boolean] When this input box is focused by the user, the text contents within the input
  676. will be selected. This is true by default.
  677. NumbersOnly: [Boolean] When true, only numeric characters and the '.' character are allowed to be input into
  678. the input box. If no text is input, the input box will display '0'.
  679. W: [Number] The width of the input box. By default, will be 150.0
  680. H: [Number] The height of the input box. By default, will be the height of the current font.
  681. ReadOnly: [Boolean] Whether this input field can be editable or not.
  682. Align: [String] Aligns the text within the input box. Options are:
  683. left: Aligns the text to the left. This will be set when this Input is focused.
  684. center: Aligns the text in the center. This is the default for when the text is not focused.
  685. Rounding: [Number] Amount of rounding to apply to the corners of the input box.
  686. MinNumber: [Number] The minimum value that can be entered into this input box. Only valid when NumbersOnly is true.
  687. MaxNumber: [Number] The maximum value that can be entered into this input box. Only valid when NumbersOnly is true.
  688. MultiLine: [Boolean] Determines whether this input control should support multiple lines. If this is true, then the
  689. SelectOnFocus flag will be false. The given text will also be sanitized to remove controls characters such as
  690. '\r'. Also, the text will be left aligned.
  691. MultiLineW: [Number] The width for which the lines of text should be wrapped at.
  692. Highlight: [Table] A list of key-values that define what words to highlight what color. Strings should be used for
  693. the word to highlight and the value should be a table defining the color.
  694. Return: [Boolean] Returns true if the user has pressed the return key while focused on this input box. If ReturnOnText
  695. is set to true, then this function will return true whenever the user has input any character into the input box.
  696. --]]
  697. function Slab.Input(Id, Options)
  698. return Input.Begin(Id, Options)
  699. end
  700. --[[
  701. GetInputText
  702. Retrieves the text entered into the focused input box. Refer to the documentation for Slab.Input for an example on how to
  703. use this function.
  704. Return: [String] Returns the text entered into the focused input box.
  705. --]]
  706. function Slab.GetInputText()
  707. return Input.GetText()
  708. end
  709. --[[
  710. GetInputNumber
  711. Retrieves the text entered into the focused input box and attempts to conver the text into a number. Will always return a valid
  712. number.
  713. Return: [Number] Returns the text entered into the focused input box as a number.
  714. --]]
  715. function Slab.GetInputNumber()
  716. local Result = tonumber(Input.GetText())
  717. if Result == nil then
  718. Result = 0
  719. end
  720. return Result
  721. end
  722. --[[
  723. GetInputCursorPos
  724. Retrieves the position of the input cursor for the focused input control. There are three values that are returned. The first one
  725. is the absolute position of the cursor with regards to the text for the control. The second is the column position of the cursor
  726. on the current line. The final value is the line number. The column will match the absolute position if the input control is not
  727. multi line.
  728. Return: [Number], [Number], [Number] The absolute position of the cursor, the column position of the cursor on the current line,
  729. and the line number of the cursor. These values will all be zero if no input control is focused.
  730. --]]
  731. function Slab.GetInputCursorPos()
  732. return Input.GetCursorPos()
  733. end
  734. --[[
  735. IsInputFocused
  736. Returns whether the input control with the given Id is focused or not.
  737. Id: [String] The Id of the input control to check.
  738. Return: [Boolean] True if the input control with the given Id is focused. False otherwise.
  739. --]]
  740. function Slab.IsInputFocused(Id)
  741. return Input.IsFocused(Id)
  742. end
  743. --[[
  744. SetInputFocus
  745. Sets the focus of the input control to the control with the given Id. The focus is set at the beginning
  746. of the next frame to avoid any input events from the current frame.
  747. Id: [String] The Id of the input control to focus.
  748. --]]
  749. function Slab.SetInputFocus(Id)
  750. Input.SetFocused(Id)
  751. end
  752. --[[
  753. SetInputCursorPos
  754. Sets the absolute text position in bytes of the focused input control. This value is applied on the next frame.
  755. This function can be combined with the SetInputFocus function to modify the cursor positioning of the desired
  756. input control. Note that the input control supports UTF8 characters so if the desired position is not a valid
  757. character, the position will be altered to find the next closest valid character.
  758. Pos: [Number] The absolute position in bytes of the text of the focused input control.
  759. --]]
  760. function Slab.SetInputCursorPos(Pos)
  761. Input.SetCursorPos(Pos)
  762. end
  763. --[[
  764. SetInputCursorPosLine
  765. Sets the column and line number of the focused input control. These values are applied on the next frame. This
  766. function behaves the same as SetInputCursorPos, but allows for setting the cursor by column and line.
  767. Column: [Number] The text position in bytes of the current line.
  768. Line: [Number] The line number to set.
  769. --]]
  770. function Slab.SetInputCursorPosLine(Column, Line)
  771. Input.SetCursorPosLine(Column, Line)
  772. end
  773. --[[
  774. BeginTree
  775. This function will render a tree item with an optional label. The tree can be expanded or collapsed based on whether
  776. the user clicked on the tree item. This function can also be nested to create a hierarchy of tree items. This function
  777. will return false when collapsed and true when expanded. If this function returns true, Slab.EndTree must be called in
  778. order for this tree item to behave properly. The hot zone of this tree item will be the height of the label and the width
  779. of the window by default.
  780. Id: [String] A string uniquely identifying this tree item within the context of the window.
  781. Options: [Table] List of options for how this tree item will behave.
  782. Label: [String] The text to be rendered for this tree item.
  783. Tooltip: [String] The text to be rendered when the user hovers over this tree item.
  784. IsLeaf: [Boolean] If this is true, this tree item will not be expandable/collapsable.
  785. OpenWithHighlight: [Boolean] If this is true, the tree will be expanded/collapsed when the user hovers over the hot
  786. zone of this tree item. If this is false, the user must click the expand/collapse icon to interact with this tree
  787. item.
  788. Icon: [Object] A user supplied image. This must be a valid Love image or the call will assert.
  789. IconPath: [String] If the Icon option is nil, then a path can be specified. Slab will load and
  790. manage the image resource.
  791. IsSelected: [Boolean] If true, will render a highlight rectangle around the tree item.
  792. IsOpen: [Boolean] Will force the tree item to be expanded.
  793. Return: [Boolean] Returns true if this tree item is expanded. Slab.EndTree must be called if this returns true.
  794. --]]
  795. function Slab.BeginTree(Id, Options)
  796. return Tree.Begin(Id, Options)
  797. end
  798. --[[
  799. EndTree
  800. Finishes up any BeginTree calls if those functions return true.
  801. Return: None.
  802. --]]
  803. function Slab.EndTree()
  804. Tree.End()
  805. end
  806. --[[
  807. BeginComboBox
  808. This function renders a non-editable input field with a drop down arrow. When the user clicks this option, a window is
  809. created and the user can supply their own Slab.TextSelectable calls to add possible items to select from. This function
  810. will return true if the combo box is opened. Slab.EndComboBox must be called if this function returns true.
  811. Example:
  812. local Options = {"Apple", "Banana", "Orange", "Pear", "Lemon"}
  813. local Options_Selected = ""
  814. if Slab.BeginComboBox('Fruits', {Selected = Options_Selected}) then
  815. for K, V in pairs(Options) do
  816. if Slab.TextSelectable(V) then
  817. Options_Selected = V
  818. end
  819. end
  820. Slab.EndComboBox()
  821. end
  822. Id: [String] A string that uniquely identifies this combo box within the context of the active window.
  823. Options: [Table] List of options that control how this combo box behaves.
  824. Tooltip: [String] Text that is rendered when the user hovers over this combo box.
  825. Selected: [String] Text that is displayed in the non-editable input box for this combo box.
  826. W: [Number] The width of the combo box. The default value is 150.0.
  827. Rounding: [Number] Amount of rounding to apply to the corners of the combo box.
  828. Return: [Boolean] This function will return true if the combo box is open.
  829. --]]
  830. function Slab.BeginComboBox(Id, Options)
  831. return ComboBox.Begin(Id, Options)
  832. end
  833. --[[
  834. EndComboBox
  835. Finishes up any BeginComboBox calls if those functions return true.
  836. Return: None.
  837. --]]
  838. function Slab.EndComboBox()
  839. ComboBox.End()
  840. end
  841. --[[
  842. Image
  843. Draws an image at the current cursor position. The Id uniquely identifies this
  844. image to manage behaviors with this image. An image can be supplied through the
  845. options or a path can be specified which Slab will manage the loading and storing of
  846. the image reference.
  847. Id: [String] A string uniquely identifying this image within the context of the current window.
  848. Options: [Table] List of options controlling how the image should be drawn.
  849. Image: [Object] A user supplied image. This must be a valid Love image or the call will assert.
  850. Path: [String] If the Image option is nil, then a path must be specified. Slab will load and
  851. manage the image resource.
  852. Rotation: [Number] The rotation value to apply when this image is drawn.
  853. Scale: [Number] The scale value to apply to both the X and Y axis.
  854. ScaleX: [Number] The scale value to apply to the X axis.
  855. ScaleY: [Number] The scale value to apply to the Y axis.
  856. Color: [Table] The color to use when rendering this image.
  857. SubX: [Number] The X-coordinate used inside the given image.
  858. SubY: [Number] The Y-coordinate used inside the given image.
  859. SubW: [Number] The width used inside the given image.
  860. SubH: [Number] The height used insided the given image.
  861. WrapX: [String] The horizontal wrapping mode for this image. The available options are 'clamp', 'repeat',
  862. 'mirroredrepeat', and 'clampzero'. For more information refer to the Love2D documentation on wrap modes at
  863. https://love2d.org/wiki/WrapMode.
  864. WrapY: [String] The vertical wrapping mode for this image. The available options are 'clamp', 'repeat',
  865. 'mirroredrepeat', and 'clampzero'. For more information refer to the Love2D documentation on wrap modes at
  866. https://love2d.org/wiki/WrapMode.
  867. Return: None.
  868. --]]
  869. function Slab.Image(Id, Options)
  870. Image.Begin(Id, Options)
  871. end
  872. --[[
  873. SameLine
  874. This forces the cursor to move back up to the same line as the previous widget. By default, all Slab widgets will
  875. advance the cursor to the next line based on the height of the current line. By using this call with other widget
  876. calls, the user will be able to set up multiple widgets on the same line to control how a window may look.
  877. Options: [Table] List of options that controls how the cursor should handle the same line.
  878. Pad: [Number] Extra padding to apply in the X direction.
  879. CenterY: [Boolean] Controls whether the cursor should be centered in the Y direction on the line. By default
  880. the line will use the NewLineSize, which is the height of the current font to center the cursor.
  881. Return: None.
  882. --]]
  883. function Slab.SameLine(Options)
  884. LayoutManager.SameLine(Options)
  885. end
  886. --[[
  887. NewLine
  888. This forces the cursor to advance to the next line based on the height of the current font.
  889. Return: None.
  890. --]]
  891. function Slab.NewLine()
  892. LayoutManager.NewLine()
  893. end
  894. --[[
  895. SetCursorPos
  896. Sets the cursor position. The default behavior is to set the cursor position relative to
  897. the current window. The absolute position can be set if the 'Absolute' option is set.
  898. Controls will only be drawn within a window. If the cursor is set outside of the current
  899. window context, the control will not be displayed.
  900. X: [Number] The X coordinate to place the cursor. If nil, then the X coordinate is not modified.
  901. Y: [Number] The Y coordinate to place the cursor. If nil, then the Y coordinate is not modified.
  902. Options: [Table] List of options that control how the cursor position should be set.
  903. Absolute: [Boolean] If true, will place the cursor using absolute coordinates.
  904. Return: None.
  905. --]]
  906. function Slab.SetCursorPos(X, Y, Options)
  907. Options = Options == nil and {} or Options
  908. Options.Absolute = Options.Absolute == nil and false or Options.Absolute
  909. if Options.Absolute then
  910. X = X == nil and Cursor.GetX() or X
  911. Y = Y == nil and Cursor.GetY() or Y
  912. Cursor.SetPosition(X, Y)
  913. else
  914. X = X == nil and Cursor.GetX() - Cursor.GetAnchorX() or X
  915. Y = Y == nil and Cursor.GetY() - Cursor.GetAnchorY() or Y
  916. Cursor.SetRelativePosition(X, Y)
  917. end
  918. end
  919. --[[
  920. GetCursorPos
  921. Gets the cursor position. The default behavior is to get the cursor position relative to
  922. the current window. The absolute position can be retrieved if the 'Absolute' option is set.
  923. Options: [Table] List of options that control how the cursor position should be retrieved.
  924. Absolute: [Boolean] If true, will return the cursor position in absolute coordinates.
  925. Return: [Number], [Number] The X and Y coordinates of the cursor.
  926. --]]
  927. function Slab.GetCursorPos(Options)
  928. Options = Options == nil and {} or Options
  929. Options.Absolute = Options.Absolute == nil and false or Options.Absolute
  930. local X, Y = Cursor.GetPosition()
  931. if not Options.Absolute then
  932. X = X - Cursor.GetAnchorX()
  933. Y = Y - Cursor.GetAnchorY()
  934. end
  935. return X, Y
  936. end
  937. --[[
  938. Properties
  939. Iterates through the table's key-value pairs and adds them to the active window. This currently only does
  940. a shallow loop and will not iterate through nested tables.
  941. TODO: Iterate through nested tables.
  942. Table: [Table] The list of properties to build widgets for.
  943. Return: None.
  944. --]]
  945. function Slab.Properties(Table)
  946. if Table ~= nil then
  947. for K, V in pairs(Table) do
  948. local Type = type(V)
  949. if Type == "boolean" then
  950. if Slab.CheckBox(V, K) then
  951. Table[K] = not Table[K]
  952. end
  953. elseif Type == "number" then
  954. Slab.Text(K .. ": ")
  955. Slab.SameLine()
  956. if Slab.Input(K, {Text = tostring(V), NumbersOnly = true, ReturnOnText = false}) then
  957. Table[K] = Slab.GetInputNumber()
  958. end
  959. elseif Type == "string" then
  960. Slab.Text(K .. ": ")
  961. Slab.SameLine()
  962. if Slab.Input(K, {Text = V, ReturnOnText = false}) then
  963. Table[K] = Slab.GetInputText()
  964. end
  965. end
  966. end
  967. end
  968. end
  969. --[[
  970. BeginListBox
  971. Begins the process of creating a list box. If this function is called, EndListBox must be called after all
  972. items have been added.
  973. Id: [String] A string uniquely identifying this list box within the context of the current window.
  974. Options: [Table] List of options controlling the behavior of the list box.
  975. W: [Number] The width of the list box. If nil, then the width of the window is used.
  976. H: [Number] The height of the list box. If nil, a default value of 150 is used. If H is 0, then
  977. the list box will stretch to the height of the window.
  978. Clear: [Boolean] Clears out the items in the list. It is recommended to only call this if the list items
  979. has changed and should not be set to true on every frame.
  980. Rounding: [Number] Amount of rounding to apply to the corners of the list box.
  981. Return: None.
  982. --]]
  983. function Slab.BeginListBox(Id, Options)
  984. ListBox.Begin(Id, Options)
  985. end
  986. --[[
  987. EndListBox
  988. Ends the list box container. Will close off the region and properly adjust the cursor.
  989. Return: None.
  990. --]]
  991. function Slab.EndListBox()
  992. ListBox.End()
  993. end
  994. --[[
  995. BeginListBoxItem
  996. Adds an item to the current list box with the given Id. The user can then draw controls however they see
  997. fit to display a single item. This allows the user to draw list items such as a texture with a name or just
  998. a text to represent the item. If this is called, EndListBoxItem must be called to complete the item.
  999. Id: [String] A string uniquely identifying this item within the context of the current list box.
  1000. Options: [Table] List of options that control the behavior of the active list item.
  1001. Selected: [Boolean] If true, will draw the item with a selection background.
  1002. Return: None.
  1003. --]]
  1004. function Slab.BeginListBoxItem(Id, Options)
  1005. ListBox.BeginItem(Id, Options)
  1006. end
  1007. --[[
  1008. IsListBoxItemClicked
  1009. Checks to see if a hot list item is clicked. This should only be called within a BeginListBoxLitem/EndListBoxItem
  1010. block.
  1011. Button: [Number] The button to check for the click of the item.
  1012. IsDoubleClick: [Boolean] Check for double-click instead of single click.
  1013. Return: [Boolean] Returns true if the active item is hovered with mouse and the requested mouse button is clicked.
  1014. --]]
  1015. function Slab.IsListBoxItemClicked(Button, IsDoubleClick)
  1016. return ListBox.IsItemClicked(Button, IsDoubleClick)
  1017. end
  1018. --[[
  1019. EndListBoxItem
  1020. Ends the current item and commits the bounds of the item to the list.
  1021. Return: None.
  1022. --]]
  1023. function Slab.EndListBoxItem()
  1024. ListBox.EndItem()
  1025. end
  1026. --[[
  1027. OpenDialog
  1028. Opens the dialog box with the given Id. If the dialog box was opened, then it is pushed onto the stack.
  1029. Calls to the BeginDialog with this same Id will return true if opened.
  1030. Id: [String] A string uniquely identifying this dialog box.
  1031. Return: None.
  1032. --]]
  1033. function Slab.OpenDialog(Id)
  1034. Dialog.Open(Id)
  1035. end
  1036. --[[
  1037. BeginDialog
  1038. Begins the dialog window with the given Id if it is open. If this function returns true, then EndDialog must be called.
  1039. Dialog boxes are windows which are centered in the center of the viewport. The dialog box cannot be moved and will
  1040. capture all input from all other windows.
  1041. Id: [String] A string uniquely identifying this dialog box.
  1042. Options: [Table] List of options that control how this dialog box behaves. These are the same parameters found
  1043. for BeginWindow, with some caveats. Certain options are overridden by the Dialog system. They are:
  1044. X, Y, Layer, AllowFocus, AllowMove, and AutoSizeWindow.
  1045. Return: [Boolean] Returns true if the dialog with the given Id is open.
  1046. --]]
  1047. function Slab.BeginDialog(Id, Options)
  1048. return Dialog.Begin(Id, Options)
  1049. end
  1050. --[[
  1051. EndDialog
  1052. Ends the dialog window if a call to BeginDialog returns true.
  1053. Return: None.
  1054. --]]
  1055. function Slab.EndDialog()
  1056. Dialog.End()
  1057. end
  1058. --[[
  1059. CloseDialog
  1060. Closes the currently active dialog box.
  1061. Return: None.
  1062. --]]
  1063. function Slab.CloseDialog()
  1064. Dialog.Close()
  1065. end
  1066. --[[
  1067. MessageBox
  1068. Opens a message box to be displayed to the user with a title and a message. Buttons can be specified through the options
  1069. table which when clicked, the string of the button is returned. This function should be called every frame when a message
  1070. box wants to be displayed.
  1071. Title: [String] The title to display for the message box.
  1072. Message: [String] The message to be displayed. The text is aligned in the center. Multi-line strings are supported.
  1073. Options: [Table] List of options to control the behavior of the message box.
  1074. Buttons: [Table] List of buttons to display with the message box. The order of the buttons are displayed from right to left.
  1075. Return: [String] The name of the button that was clicked. If none was clicked, an emtpy string is returned.
  1076. --]]
  1077. function Slab.MessageBox(Title, Message, Options)
  1078. Options = Options == nil and {} or Options
  1079. Options.Buttons = Options.Buttons == nil and {"OK"} or Options.Buttons
  1080. local Result = ""
  1081. Slab.OpenDialog('MessageBox')
  1082. if Slab.BeginDialog('MessageBox', {Title = Title, Border = 12}) then
  1083. Slab.BeginLayout('MessageBox_Message_Layout', {AlignX = 'center', AlignY = 'center'})
  1084. local TextW = math.min(Slab.GetTextWidth(Message), love.graphics.getWidth() * 0.80)
  1085. Slab.Textf(Message, {Align = 'center', W = TextW})
  1086. Slab.EndLayout()
  1087. Slab.NewLine()
  1088. Slab.NewLine()
  1089. Slab.BeginLayout('MessageBox_Buttons_Layout', {AlignX = 'right', AlignY = 'bottom'})
  1090. for I, V in ipairs(Options.Buttons) do
  1091. if Button.Begin(V) then
  1092. Result = V
  1093. end
  1094. Slab.SameLine()
  1095. end
  1096. Slab.EndLayout()
  1097. if Result ~= "" then
  1098. Slab.CloseDialog()
  1099. end
  1100. Slab.EndDialog()
  1101. end
  1102. return Result
  1103. end
  1104. --[[
  1105. FileDialog
  1106. Opens up a dialog box that displays a file explorer for opening or saving files or directories. This function does not create any file
  1107. handles, it just returns the list of files selected by the user.
  1108. Options: [Table] List of options that control the behavior of the file dialog.
  1109. AllowMultiSelect: [Boolean] Allows the user to select multiple items in the file dialog.
  1110. Directory: [String] The starting directory when the file dialog is open. If none is specified, the dialog
  1111. will start at love.filesystem.getSourceBaseDirectory and the dialog will remember the last
  1112. directory navigated to by the user between calls to this function.
  1113. Type: [String] The type of file dialog to use. The options are:
  1114. openfile: This is the default method. The user will have access to both directories and files. However,
  1115. only file selections are returned.
  1116. opendirectory: This type is used to filter the file dialog for directories only. No files will appear
  1117. in the list.
  1118. savefile: This type is used to select a name of a file to save. The user will be prompted if they wish to overwrite
  1119. an existing file.
  1120. Filters: [Table] A list of filters the user can select from when browsing files. The table can contain tables or strings.
  1121. Table: If a table is used for a filter, it should contain two elements. The first element is the filter while the second
  1122. element is the description of the filter e.g. {"*.lua", "Lua Files"}
  1123. String: If a raw string is used, then it should just be the filter. It is recommended to use the table option since a
  1124. description can be given for each filter.
  1125. Return: [Table] Returns items for how the user interacted with this file dialog.
  1126. Button: [String] The button the user clicked. Will either be OK or Cancel.
  1127. Files: [Table] An array of selected file items the user selected when OK is pressed. Will be empty otherwise.
  1128. --]]
  1129. function Slab.FileDialog(Options)
  1130. return Dialog.FileDialog(Options)
  1131. end
  1132. --[[
  1133. ColorPicker
  1134. Displays a window to allow the user to pick a hue and saturation value of a color. This should be called every frame and the result
  1135. should be handled to stop displaying the color picker and store the resulting color.
  1136. Options: [Table] List of options that control the behavior of the color picker.
  1137. Color: [Table] The color to modify. This should be in the format of 0-1 for each color component (RGBA).
  1138. Return: [Table] Returns the button and color the user has selected.
  1139. Button: [String] The button the user clicked. Will either be OK or Cancel.
  1140. Color: [Table] The new color the user has chosen. This will always be returned.
  1141. --]]
  1142. function Slab.ColorPicker(Options)
  1143. return ColorPicker.Begin(Options)
  1144. end
  1145. --[[
  1146. IsMouseDown
  1147. Determines if a given mouse button is down.
  1148. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1149. Return: [Boolean] True if the given button is down. False otherwise.
  1150. --]]
  1151. function Slab.IsMouseDown(Button)
  1152. return Mouse.IsPressed(Button and Button or 1)
  1153. end
  1154. --[[
  1155. IsMouseClicked
  1156. Determines if a given mouse button changes state from up to down this frame.
  1157. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1158. Return: [Boolean] True if the given button changes state from up to down. False otherwise.
  1159. --]]
  1160. function Slab.IsMouseClicked(Button)
  1161. return Mouse.IsClicked(Button and Button or 1)
  1162. end
  1163. --[[
  1164. IsMouseReleased
  1165. Determines if a given mouse button changes state from down to up this frame.
  1166. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1167. Return: [Boolean] True if the given button changes state from down to up. False otherwise.
  1168. --]]
  1169. function Slab.IsMouseReleased(Button)
  1170. return Mouse.IsReleased(Button and Button or 1)
  1171. end
  1172. --[[
  1173. IsMouseDoubleClicked
  1174. Determines if a given mouse button has been clicked twice within a given time frame.
  1175. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1176. Return: [Boolean] True if the given button was double clicked. False otherwise.
  1177. --]]
  1178. function Slab.IsMouseDoubleClicked(Button)
  1179. return Mouse.IsDoubleClicked(Button and Button or 1)
  1180. end
  1181. --[[
  1182. IsMouseDragging
  1183. Determines if a given mouse button is down and there has been movement.
  1184. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1185. Return: [Boolean] True if the button is held down and is moving. False otherwise.
  1186. --]]
  1187. function Slab.IsMouseDragging(Button)
  1188. return Mouse.IsDragging(Button and Button or 1)
  1189. end
  1190. --[[
  1191. GetMousePosition
  1192. Retrieves the current mouse position in the viewport.
  1193. Return: [Number], [Number] The X and Y coordinates of the mouse position.
  1194. --]]
  1195. function Slab.GetMousePosition()
  1196. return Mouse.Position()
  1197. end
  1198. --[[
  1199. GetMousePositionWindow
  1200. Retrieves the current mouse position within the current window. This position will include any transformations
  1201. added to the window such as scrolling.
  1202. Return: [Number], [Number] The X and Y coordinates of the mouse position within the window.
  1203. --]]
  1204. function Slab.GetMousePositionWindow()
  1205. return Window.GetMousePosition()
  1206. end
  1207. --[[
  1208. GetMouseDelta
  1209. Retrieves the change in mouse coordinates from the last frame.
  1210. Return: [Number], [Number] The X and Y coordinates of the delta from the last frame.
  1211. --]]
  1212. function Slab.GetMouseDelta()
  1213. return Mouse.GetDelta()
  1214. end
  1215. --[[
  1216. IsControlHovered
  1217. Checks to see if the last control added to the window is hovered by the mouse.
  1218. Return: [Boolean] True if the last control is hovered, false otherwise.
  1219. --]]
  1220. function Slab.IsControlHovered()
  1221. local Result = Window.IsItemHot()
  1222. if not Result then
  1223. local X, Y = Slab.GetMousePositionWindow()
  1224. Result = Cursor.IsInItemBounds(X, Y)
  1225. end
  1226. return Result
  1227. end
  1228. --[[
  1229. IsControlClicked
  1230. Checks to see if the previous control is hovered and clicked.
  1231. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1232. Return: [Boolean] True if the previous control is hovered and clicked. False otherwise.
  1233. --]]
  1234. function Slab.IsControlClicked(Button)
  1235. return Slab.IsControlHovered() and Slab.IsMouseClicked(Button)
  1236. end
  1237. --[[
  1238. GetControlSize
  1239. Retrieves the last declared control's size.
  1240. Return: [Number], [Number] The width and height of the last control declared.
  1241. --]]
  1242. function Slab.GetControlSize()
  1243. local X, Y, W, H = Cursor.GetItemBounds()
  1244. return W, H
  1245. end
  1246. --[[
  1247. IsVoidHovered
  1248. Checks to see if any non-Slab area of the viewport is hovered.
  1249. Return: [Boolean] True if any non-Slab area of the viewport is hovered. False otherwise.
  1250. --]]
  1251. function Slab.IsVoidHovered()
  1252. return Region.GetHotInstanceId() == '' and not Region.IsScrolling()
  1253. end
  1254. --[[
  1255. IsVoidClicked
  1256. Checks to see if any non-Slab area of the viewport is clicked.
  1257. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1258. Return: [Boolean] True if any non-Slab area of the viewport is clicked. False otherwise.
  1259. --]]
  1260. function Slab.IsVoidClicked(Button)
  1261. return Slab.IsMouseClicked(Button) and Slab.IsVoidHovered()
  1262. end
  1263. --[[
  1264. IsKeyDown
  1265. Checks to see if a specific key is held down. The key should be one of the love defined KeyConstant which the list can
  1266. be found at https://love2d.org/wiki/KeyConstant.
  1267. Key: [String] A love defined key constant.
  1268. Return: [Boolean] True if the key is held down. False otherwise.
  1269. --]]
  1270. function Slab.IsKeyDown(Key)
  1271. return Keyboard.IsDown(Key)
  1272. end
  1273. --[[
  1274. IsKeyPressed
  1275. Checks to see if a specific key state went from up to down this frame. The key should be one of the love defined KeyConstant which the list can
  1276. be found at https://love2d.org/wiki/KeyConstant.
  1277. Key: [String] A love defined key constant.
  1278. Return: [Boolean] True if the key state went from up to down this frame. False otherwise.
  1279. --]]
  1280. function Slab.IsKeyPressed(Key)
  1281. return Keyboard.IsPressed(Key, true)
  1282. end
  1283. --[[
  1284. IsKeyPressed
  1285. Checks to see if a specific key state went from down to up this frame. The key should be one of the love defined KeyConstant which the list can
  1286. be found at https://love2d.org/wiki/KeyConstant.
  1287. Key: [String] A love defined key constant.
  1288. Return: [Boolean] True if the key state went from down to up this frame. False otherwise.
  1289. --]]
  1290. function Slab.IsKeyReleased(Key)
  1291. return Keyboard.IsReleased(Key)
  1292. end
  1293. --[[
  1294. Rectangle
  1295. Draws a rectangle at the current cursor position for the active window.
  1296. Options: [Table] List of options that control how this rectangle is displayed.
  1297. Mode: [String] Whether this rectangle should be filled or outlined. The default value is 'fill'.
  1298. W: [Number] The width of the rectangle.
  1299. H: [Number] The height of the rectangle.
  1300. Color: [Table] The color to use for this rectangle.
  1301. Rounding: [Number] or [Table]
  1302. [Number] Amount of rounding to apply to all corners.
  1303. [Table] Define the rounding for each corner. The order goes top left, top right, bottom right, and bottom left.
  1304. Outline: [Boolean] If the Mode option is 'fill', this option will allow an outline to be drawn.
  1305. OutlineColor: [Table] The color to use for the outline if requested.
  1306. Segments: [Number] Number of points to add for each corner if rounding is requested.
  1307. Return: None.
  1308. --]]
  1309. function Slab.Rectangle(Options)
  1310. Shape.Rectangle(Options)
  1311. end
  1312. --[[
  1313. Circle
  1314. Draws a circle at the current cursor position plus the radius for the active window.
  1315. Options: [Table] List of options that control how this circle is displayed.
  1316. Mode: [String] Whether this circle should be filled or outlined. The default value is 'fill'.
  1317. Radius: [Number] The size of the circle.
  1318. Color: [Table] The color to use for the circle.
  1319. Segments: [Number] The number of segments used for drawing the circle.
  1320. Return: None.
  1321. --]]
  1322. function Slab.Circle(Options)
  1323. Shape.Circle(Options)
  1324. end
  1325. --[[
  1326. Triangle
  1327. Draws a triangle at the current cursor position plus the radius for the active window.
  1328. Option: [Table] List of options that control how this triangle is displayed.
  1329. Mode: [String] Whether this triangle should be filled or outlined. The default value is 'fill'.
  1330. Radius: [Number] The distance from the center of the triangle.
  1331. Rotation: [Number] The rotation of the triangle in degrees.
  1332. Color: [Table] The color to use for the triangle.
  1333. Return: None.
  1334. --]]
  1335. function Slab.Triangle(Options)
  1336. Shape.Triangle(Options)
  1337. end
  1338. --[[
  1339. Line
  1340. Draws a line starting at the current cursor position and going to the defined points in this function.
  1341. X2: [Number] The X coordinate for the destination.
  1342. Y2: [Number] The Y coordinate for the destination.
  1343. Option: [Table] List of options that control how this line is displayed.
  1344. Width: [Number] How thick the line should be.
  1345. Color: [Table] The color to use for the line.
  1346. Return: None.
  1347. --]]
  1348. function Slab.Line(X2, Y2, Options)
  1349. Shape.Line(X2, Y2, Options)
  1350. end
  1351. --[[
  1352. Curve
  1353. Draws a bezier curve with the given points as control points. The points should be defined in local space. Slab will translate the curve to the
  1354. current cursor position. There should two or more points defined for a proper curve.
  1355. Points: [Table] List of points to define the control points of the curve.
  1356. Options: [Table] List of options that control how this curve is displayed.
  1357. Color: [Table] The color to use for this curve.
  1358. Depth: [Number] The number of recursive subdivision steps to use when rendering the curve. If nil, the default LÖVE 2D value is used which is 5.
  1359. Return: None.
  1360. --]]
  1361. function Slab.Curve(Points, Options)
  1362. Shape.Curve(Points, Options)
  1363. end
  1364. --[[
  1365. GetCurveControlPointCount
  1366. Returns the number of control points defined with the last call to Curve.
  1367. Return: [Number] The number of control points defined for the previous curve.
  1368. --]]
  1369. function Slab.GetCurveControlPointCount()
  1370. return Shape.GetCurveControlPointCount()
  1371. end
  1372. --[[
  1373. GetCurveControlPoint
  1374. Returns the point for the given control point index. This point by default will be in local space defined by the points given in the Curve function.
  1375. The translated position can be requested by setting the LocalSpace option to false.
  1376. Index: [Number] The index of the control point to retrieve.
  1377. Options: [Table] A list of options that control what is returned by this function.
  1378. LocalSpace: [Boolean] Returns either the translated or untranslated control point. This is true by default.
  1379. Return: [Number], [Number] The translated X, Y coordinates of the given control point.
  1380. --]]
  1381. function Slab.GetCurveControlPoint(Index, Options)
  1382. return Shape.GetCurveControlPoint(Index, Options)
  1383. end
  1384. --[[
  1385. EvaluateCurve
  1386. Returns the point at the given time. The time value should be between 0 and 1 inclusive. The point returned will be in local space. For the translated
  1387. position, set the LocalSpace option to false.
  1388. Time: [Number] The time on the curve between 0 and 1.
  1389. Options: [Table] A list of options that control what is returned by this function.
  1390. LocalSpace: [Boolean] Returnes either the translated or untranslated control point. This is true by default.
  1391. Return: [Number], [Number] The X and Y coordinates at the given time on the curve.
  1392. --]]
  1393. function Slab.EvaluateCurve(Time, Options)
  1394. return Shape.EvaluateCurve(Time, Options)
  1395. end
  1396. --[[
  1397. EvaluateCurveMouse
  1398. Returns the point on the curve at the given X-coordinate of the mouse relative to the end points of the curve.
  1399. Options: [Table] A list of options that control what is returned by this function.
  1400. Refer to the documentation for EvaluateCurve for the list of options.
  1401. Return: [Number], [Number] The X and Y coordinates at the given X mouse position on the curve.
  1402. --]]
  1403. function Slab.EvaluateCurveMouse(Options)
  1404. local X1, Y1 = Slab.GetCurveControlPoint(1, {LocalSpace = false})
  1405. local X2, Y2 = Slab.GetCurveControlPoint(Slab.GetCurveControlPointCount(), {LocalSpace = false})
  1406. local Left = math.min(X1, X2)
  1407. local W = math.abs(X2 - X1)
  1408. local X, Y = Slab.GetMousePositionWindow()
  1409. local Offset = math.max(X - Left, 0.0)
  1410. Offset = math.min(Offset, W)
  1411. return Slab.EvaluateCurve(Offset / W, Options)
  1412. end
  1413. --[[
  1414. Polygon
  1415. Renders a polygon with the given points. The points should be defined in local space. Slab will translate the position to the current cursor position.
  1416. Points: [Table] List of points that define this polygon.
  1417. Options: [Table] List of options that control how this polygon is drawn.
  1418. Color: [Table] The color to render this polygon.
  1419. Mode: [String] Whether to use 'fill' or 'line' to draw this polygon. The default is 'fill'.
  1420. Return: None.
  1421. --]]
  1422. function Slab.Polygon(Points, Options)
  1423. Shape.Polygon(Points, Options)
  1424. end
  1425. --[[
  1426. BeginStat
  1427. Starts the timer for the specific stat in the given category.
  1428. Name: [String] The name of the stat to capture.
  1429. Category: [String] The category this stat belongs to.
  1430. Return: [Number] The handle identifying this stat capture.
  1431. --]]
  1432. function Slab.BeginStat(Name, Category)
  1433. return Stats.Begin(Name, Category)
  1434. end
  1435. --[[
  1436. EndStat
  1437. Ends the timer for the stat assigned to the given handle.
  1438. Handle: [Number] The handle identifying a BeginStat call.
  1439. Return: None.
  1440. --]]
  1441. function Slab.EndStat(Handle)
  1442. Stats.End(Handle)
  1443. end
  1444. --[[
  1445. EnableStats
  1446. Sets the enabled state of the stats system. The system is disabled by default.
  1447. Enable: [Boolean] The new state of the states system.
  1448. Return: None.
  1449. --]]
  1450. function Slab.EnableStats(Enable)
  1451. Stats.SetEnabled(Enable)
  1452. end
  1453. --[[
  1454. IsStatsEnabled
  1455. Query whether the stats system is enabled or disabled.
  1456. Return: [Boolean] Returns whether the stats system is enabled or disabled.
  1457. --]]
  1458. function Slab.IsStatsEnabled()
  1459. return Stats.IsEnabled()
  1460. end
  1461. --[[
  1462. FlushStats
  1463. Resets the stats system to an empty state.
  1464. Return: None.
  1465. --]]
  1466. function Slab.FlushStats()
  1467. Stats.Flush()
  1468. end
  1469. --[[
  1470. BeginLayout
  1471. Enables the layout manager and positions the controls between this call and EndLayout based on the given options. The anchor
  1472. position for the layout is determined by the current cursor position on the Y axis. The horizontal position is not anchored.
  1473. Layouts are stacked, so there can be layouts within parent layouts.
  1474. Id: [String] The Id of this layout.
  1475. Options: [Table] List of options that control how this layout behaves.
  1476. AlignX: [String] Defines how the controls should be positioned horizontally in the window. The available options are
  1477. 'left', 'center', or 'right'. The default option is 'left'.
  1478. AlignY: [String] Defines how the controls should be positioned vertically in the window. The available options are
  1479. 'top', 'center', or 'bottom'. The default option is 'top'. The top is determined by the current cursor position.
  1480. AlignRowY: [String] Defines how the controls should be positioned vertically within a row. The available options are
  1481. 'top', 'center', or 'bottom'. The default option is 'top'.
  1482. Ignore: [Boolean] Should this layout ignore positioning of controls. This is useful if certain controls need custom
  1483. positioning within a layout.
  1484. ExpandW: [Boolean] If true, will expand all controls' width within the row to the size of the window.
  1485. ExpandH: [Boolean] If true, will expand all controls' height within the row and the size of the window.
  1486. AnchorX: [Boolean] Anchors the layout management at the current X cursor position. The size is calculated using this position.
  1487. The default value for this is false.
  1488. AnchorY: [Boolean] Anchors the layout management at the current Y cursor position. The size is calculated using this position.
  1489. The default value for this is true.
  1490. Columns: [Number] The number of columns to use for this layout. The default value is 1.
  1491. Return: None.
  1492. --]]
  1493. function Slab.BeginLayout(Id, Options)
  1494. LayoutManager.Begin(Id, Options)
  1495. end
  1496. --[[
  1497. EndLayout
  1498. Ends the currently active layout. Each BeginLayout call must have a matching EndLayout. Failure to do so will result in
  1499. an assertion.
  1500. Return: None.
  1501. --]]
  1502. function Slab.EndLayout()
  1503. LayoutManager.End()
  1504. end
  1505. --[[
  1506. SetLayoutColumn
  1507. Sets the current active column.
  1508. Index: [Number] The index of the column to be active.
  1509. Return: None.
  1510. --]]
  1511. function Slab.SetLayoutColumn(Index)
  1512. LayoutManager.SetColumn(Index)
  1513. end
  1514. --[[
  1515. GetLayoutSize
  1516. Retrieves the size of the active layout. If there are columns, then the size of the column is returned.
  1517. Return: [Number], [Number] The width and height of the active layout. 0 is returned if no layout is active.
  1518. --]]
  1519. function Slab.GetLayoutSize()
  1520. return LayoutManager.GetActiveSize()
  1521. end
  1522. --[[
  1523. BeginTab
  1524. Begins the process of collecting windows to be displayed in a tabbed window. This controls which window should
  1525. be visible and allows the user to select the next visible window. This affects all windows placed in between
  1526. the BeginTab/EndTab calls. However, the Tab system will override certain options of a window. Tabbed windows
  1527. cannot be auto-sized and will be forced to have a fixed width and height which will carry over to all other
  1528. windows. All BeginTab calls should have a corresponding EndTab call.
  1529. Id: [String] The Id of this tab window.
  1530. Options: [Table] The list of options that control how this Tab behaves. Currently not used.
  1531. Return: None.
  1532. --]]
  1533. function Slab.BeginTab(Id, Options)
  1534. Tab.Begin(Id, Options)
  1535. end
  1536. --[[
  1537. EndTab
  1538. Ends the process of collecting windows to be displayed in a tabbed window.
  1539. Return: None.
  1540. --]]
  1541. function Slab.EndTab()
  1542. local WinId = Tab.GetActiveWinId()
  1543. Tab.End(Window.IsInstanceObstructedAtMouse(WinId))
  1544. end
  1545. --[[
  1546. SetDockEnabled
  1547. Alter what docks the user may dock windows to.
  1548. Options: [Table] Key-value pairs for which docks are enabled or disabled. The key should be a string and the value
  1549. should be true or false. The available keys are 'Left', 'Right', and 'Bottom'.
  1550. Return: None.
  1551. --]]
  1552. function Slab.SetDockEnabled(Options)
  1553. Dock.SetEnabled(Options)
  1554. end
  1555. return Slab