API.lua 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  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 DrawCommands = require(SLAB_PATH .. '.Internal.Core.DrawCommands')
  30. local Image = require(SLAB_PATH .. '.Internal.UI.Image')
  31. local Input = require(SLAB_PATH .. '.Internal.UI.Input')
  32. local Keyboard = require(SLAB_PATH .. '.Internal.Input.Keyboard')
  33. local ListBox = require(SLAB_PATH .. '.Internal.UI.ListBox')
  34. local Mouse = require(SLAB_PATH .. '.Internal.Input.Mouse')
  35. local Menu = require(SLAB_PATH .. '.Internal.UI.Menu')
  36. local MenuState = require(SLAB_PATH .. '.Internal.UI.MenuState')
  37. local MenuBar = require(SLAB_PATH .. '.Internal.UI.MenuBar')
  38. local Region = require(SLAB_PATH .. '.Internal.UI.Region')
  39. local Separator = require(SLAB_PATH .. '.Internal.UI.Separator')
  40. local Shape = require(SLAB_PATH .. '.Internal.UI.Shape')
  41. local Stats = require(SLAB_PATH .. '.Internal.Core.Stats')
  42. local Style = require(SLAB_PATH .. '.Style')
  43. local Text = require(SLAB_PATH .. '.Internal.UI.Text')
  44. local Tree = require(SLAB_PATH .. '.Internal.UI.Tree')
  45. local Window = require(SLAB_PATH .. '.Internal.UI.Window')
  46. --[[
  47. Slab
  48. Slab is an immediate mode GUI toolkit for the Love 2D framework. This library is designed to
  49. allow users to easily add this library to their existing Love 2D projects and quickly create
  50. tools to enable them to iterate on their ideas quickly. The user should be able to utilize this
  51. library with minimal integration steps and is completely written in Lua and utilizes
  52. the Love 2D API. No compiled binaries are required and the user will have access to the source
  53. so that they may make adjustments that meet the needs of their own projects and tools. Refer
  54. to main.lua and SlabTest.lua for example usage of this library.
  55. Supported Version: 11.2.0
  56. API:
  57. Initialize
  58. GetVersion
  59. GetLoveVersion
  60. Update
  61. Draw
  62. GetStyle
  63. Window:
  64. BeginWindow
  65. EndWindow
  66. GetWindowPosition
  67. GetWindowSize
  68. GetWindowContentSize
  69. GetWindowActiveSize
  70. BeginColumn
  71. EndColumn
  72. Menu:
  73. BeginMainMenuBar
  74. EndMainMenuBar
  75. BeginMenuBar
  76. EndMenuBar
  77. BeginMenu
  78. EndMenu
  79. BeginContextMenuItem
  80. BeginContextMenuWindow
  81. EndContextMenu
  82. MenuItem
  83. MenuItemChecked
  84. Separator
  85. Button
  86. RadioButton
  87. Text
  88. TextSelectable
  89. Textf
  90. CheckBox
  91. Input
  92. GetInputText
  93. GetInputNumber
  94. BeginTree
  95. EndTree
  96. BeginComboBox
  97. EndComboBox
  98. Image
  99. Cursor:
  100. SameLine
  101. NewLine
  102. SetCursorPos
  103. GetCursorPos
  104. Properties
  105. ListBox:
  106. BeginListBox
  107. EndListBox
  108. BeginListBoxItem
  109. IsListBoxItemClicked
  110. EndListBoxItem
  111. Dialog:
  112. OpenDialog
  113. BeginDialog
  114. EndDialog
  115. CloseDialog
  116. MessageBox
  117. FileDialog
  118. Mouse:
  119. IsMouseDown
  120. IsMouseClicked
  121. IsMouseReleased
  122. IsMouseDoubleClicked
  123. IsMouseDragging
  124. GetMousePosition
  125. GetMouseDelta
  126. Control:
  127. IsControlHovered
  128. IsControlClicked
  129. IsVoidHovered
  130. IsVoidClicked
  131. Keyboard:
  132. IsKeyDown
  133. IsKeyPressed
  134. IsKeyReleased
  135. Shape:
  136. Rectangle
  137. --]]
  138. local Slab = {}
  139. -- Slab version numbers.
  140. local Version_Major = 0
  141. local Version_Minor = 4
  142. local Version_Revision = 0
  143. local FrameNumber = 0
  144. local function TextInput(Ch)
  145. Input.Text(Ch)
  146. if love.textinput ~= nil then
  147. love.textinput(Ch)
  148. end
  149. end
  150. local function WheelMoved(X, Y)
  151. Window.WheelMoved(X, Y)
  152. if love.wheelmoved ~= nil then
  153. love.wheelmoved(X, Y)
  154. end
  155. end
  156. --[[
  157. Initialize
  158. Initializes Slab and hooks into the required events. This function should be called in love.load.
  159. args: [Table] The list of parameters passed in by the user on the command-line. This should be passed in from
  160. love.load function.
  161. Return: None.
  162. --]]
  163. function Slab.Initialize(args)
  164. Style.API.Initialize()
  165. love.handlers['textinput'] = TextInput
  166. love.handlers['wheelmoved'] = WheelMoved
  167. end
  168. --[[
  169. GetVersion
  170. Retrieves the current version of Slab being used as a string.
  171. Return: [String] String of the current Slab version.
  172. --]]
  173. function Slab.GetVersion()
  174. return string.format("%d.%d.%d", Version_Major, Version_Minor, Version_Revision)
  175. end
  176. --[[
  177. GetLoveVersion
  178. Retrieves the current version of Love being used as a string.
  179. Return: [String] String of the current Love version.
  180. --]]
  181. function Slab.GetLoveVersion()
  182. local Major, Minor, Revision, Codename = love.getVersion()
  183. return string.format("%d.%d.%d - %s", Major, Minor, Revision, Codename)
  184. end
  185. --[[
  186. Update
  187. Updates the input state and states of various widgets. This function must be called every frame.
  188. This should be called before any Slab calls are made to ensure proper responses to Input are made.
  189. dt: [Number] The delta time for the frame. This should be passed in from love.update.
  190. Return: None.
  191. --]]
  192. function Slab.Update(dt)
  193. FrameNumber = FrameNumber + 1
  194. Stats.Reset()
  195. Stats.Begin('Frame')
  196. Stats.Begin('Update')
  197. Mouse.Update()
  198. Keyboard.Update()
  199. Input.Update(dt)
  200. DrawCommands.Reset()
  201. Window.Reset()
  202. Window.SetFrameNumber(FrameNumber)
  203. if MenuState.IsOpened then
  204. MenuState.WasOpened = MenuState.IsOpened
  205. if Mouse.IsClicked(1) then
  206. MenuState.RequestClose = true
  207. end
  208. end
  209. Stats.End('Update')
  210. end
  211. --[[
  212. Draw
  213. This function will execute all buffered draw calls from the various Slab calls made prior. This
  214. function should be called from love.draw and should be called at the very to ensure Slab is rendered
  215. above the user's workspace.
  216. Return: None.
  217. --]]
  218. function Slab.Draw()
  219. Stats.Begin('Draw')
  220. Window.Validate()
  221. if MenuState.RequestClose then
  222. Menu.Close()
  223. MenuBar.Clear()
  224. end
  225. Mouse.UpdateCursor()
  226. if Mouse.IsReleased(1) then
  227. Button.ClearClicked()
  228. end
  229. DrawCommands.Execute()
  230. Stats.End('Draw')
  231. Stats.End('Frame')
  232. end
  233. --[[
  234. GetStyle
  235. Retrieve the style table associated with the current instance of Slab. This will allow the user to add custom styling
  236. to their controls.
  237. Return: [Table] The style table.
  238. --]]
  239. function Slab.GetStyle()
  240. return Style
  241. end
  242. --[[
  243. BeginWindow
  244. This function begins the process of drawing widgets to a window. This function must be followed up with
  245. an EndWindow call to ensure proper behavior of drawing windows.
  246. Id: [String] A unique string identifying this window in the project.
  247. Options: [Table] List of options that control how this window will behave.
  248. X: [Number] The X position to start rendering the window at.
  249. Y: [Number] The Y position to start rendering the window at.
  250. W: [Number] The starting width of the window.
  251. H: [Number] The starting height of the window.
  252. ContentW: [Number] The starting width of the content contained within this window.
  253. ContentH: [Number] The starting height of the content contained within this window.
  254. BgColor: [Table] The background color value for this window. Will use the default style WindowBackgroundColor if this is empty.
  255. Title: [String] The title to display for this window. If emtpy, no title bar will be rendered and the window will not be movable.
  256. AllowMove: [Boolean] Controls whether the window is movable within the title bar area. The default value is true.
  257. AllowResize: [Boolean] Controls whether the window is resizable. The default value is true. AutoSizeWindow must be false for this to work.
  258. AllowFocus: [Boolean] Controls whether the window can be focused. The default value is true.
  259. Border: [Number] The value which controls how much empty space should be left between all sides of the window from the content.
  260. The default value is 4.0
  261. NoOutline: [Boolean] Controls whether an outline should not be rendered. The default value is false.
  262. 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
  263. system. The default value is false.
  264. AutoSizeWindow: [Boolean] Automatically updates the window size to match the content size. The default value is true.
  265. AutoSizeWindowW: [Boolean] Automatically update the window width to match the content size. This value is taken from AutoSizeWindow by default.
  266. AutoSizeWindowH: [Boolean] Automatically update the window height to match the content size. This value is taken from AutoSizeWindow by default.
  267. AutoSizeContent: [Boolean] The content size of the window is automatically updated with each new widget. The default value is true.
  268. Layer: [String] The layer to which to draw this window. This is used internally and should be ignored by the user.
  269. ResetPosition: [Boolean] Determines if the window should reset any delta changes to its position.
  270. ResetSize: [Boolean] Determines if the window should reset any delta changes to its size.
  271. ResetContent: [Boolean] Determines if the window should reset any delta changes to its content size.
  272. ResetLayout: [Boolean] Will reset the position, size, and content. Short hand for the above 3 flags.
  273. SizerFilter: [Table] Specifies what sizers are enabled for the window. If nothing is specified, all sizers are available. The values can
  274. be: NW, NE, SW, SE, N, S, E, W
  275. CanObstruct: [Boolean] Sets whether this window is considered for obstruction of other windows and their controls. The default value is true.
  276. Rounding: [Number] Amount of rounding to apply to the corners of the window.
  277. Columns: [Number] The number of columns for this window. Must be larger than 1 for columns to work properly.
  278. Return: None
  279. --]]
  280. function Slab.BeginWindow(Id, Options)
  281. Window.Begin(Id, Options)
  282. end
  283. --[[
  284. EndWindow
  285. This function must be called after a BeginWindow and associated widget calls. If the user fails to call this, an assertion will be thrown
  286. to alert the user.
  287. Return: None.
  288. --]]
  289. function Slab.EndWindow()
  290. Window.End()
  291. end
  292. --[[
  293. GetWindowPosition
  294. Retrieves the active window's position.
  295. Return: [Number], [Number] The X and Y position of the active window.
  296. --]]
  297. function Slab.GetWindowPosition()
  298. return Window.GetPosition()
  299. end
  300. --[[
  301. GetWindowSize
  302. Retrieves the active window's size.
  303. Return: [Number], [Number] The width and height of the active window.
  304. --]]
  305. function Slab.GetWindowSize()
  306. return Window.GetSize()
  307. end
  308. --[[
  309. GetWindowContentSize
  310. Retrieves the active window's content size.
  311. Return: [Number], [Number] The width and height of the active window content.
  312. --]]
  313. function Slab.GetWindowContentSize()
  314. return Window.GetContentSize()
  315. end
  316. --[[
  317. GetWindowActiveSize
  318. Retrieves the active window's active size minus the borders. This could be the size of the window or
  319. the size of the current column.
  320. Return: [Number], [Number] The width and height of the window's active bounds.
  321. --]]
  322. function Slab.GetWindowActiveSize()
  323. return Window.GetBorderlessSize()
  324. end
  325. --[[
  326. BeginColumn
  327. The start of a column. EndColumn must be called after a call to BeginColumn and all controls have been rendered.
  328. Index: [Number] The index to the column to add controls to. This must be a valid column between 1 and the max column index
  329. defined by the Columns option in BeginWindow.
  330. Return: None.
  331. --]]
  332. function Slab.BeginColumn(Index)
  333. Window.BeginColumn(Index)
  334. end
  335. --[[
  336. EndColumn
  337. The end of a column. Must be called after a BeginColumn call.
  338. Return: None.
  339. --]]
  340. function Slab.EndColumn()
  341. Window.EndColumn()
  342. end
  343. --[[
  344. BeginMainMenuBar
  345. This function begins the process for setting up the main menu bar. This should be called outside of any BeginWindow/EndWindow calls.
  346. The user should only call EndMainMenuBar if this function returns true. Use BeginMenu/EndMenu calls to add menu items on the main menu bar.
  347. Example:
  348. if Slab.BeginMainMenuBar() then
  349. if Slab.BeginMenu("File") then
  350. if Slab.MenuItem("Quit") then
  351. love.event.quit()
  352. end
  353. Slab.EndMenu()
  354. end
  355. Slab.EndMainMenuBar()
  356. end
  357. Return: [Boolean] Returns true if the main menu bar process has started.
  358. --]]
  359. function Slab.BeginMainMenuBar()
  360. Cursor.SetPosition(0.0, 0.0)
  361. return Slab.BeginMenuBar(true)
  362. end
  363. --[[
  364. EndMainMenuBar
  365. This function should be called if BeginMainMenuBar returns true.
  366. Return: None.
  367. --]]
  368. function Slab.EndMainMenuBar()
  369. Slab.EndMenuBar()
  370. end
  371. --[[
  372. BeginMenuBar
  373. This function begins the process of rendering a menu bar for a window. This should only be called within a BeginWindow/EndWindow context.
  374. IsMainMenuBar: [Boolean] Is this menu bar for the main viewport. Used internally. Should be ignored for all other calls.
  375. Return: [Boolean] Returns true if the menu bar process has started.
  376. --]]
  377. function Slab.BeginMenuBar(IsMainMenuBar)
  378. return MenuBar.Begin(IsMainMenuBar)
  379. end
  380. --[[
  381. EndMenuBar
  382. This function should be called if BeginMenuBar returns true.
  383. Return: None.
  384. --]]
  385. function Slab.EndMenuBar()
  386. MenuBar.End()
  387. end
  388. --[[
  389. BeginMenu
  390. Adds a menu item that when the user hovers over, opens up an additional context menu. When used within a menu bar, BeginMenu calls
  391. 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
  392. the user more options are available. If this function returns true, the user must call EndMenu.
  393. Label: [String] The label to display for this menu.
  394. Return: [Boolean] Returns true if the menu item is being hovered.
  395. --]]
  396. function Slab.BeginMenu(Label)
  397. return Menu.BeginMenu(Label)
  398. end
  399. --[[
  400. EndMenu
  401. Finishes up a BeginMenu. This function must be called if BeginMenu returns true.
  402. Return: None.
  403. --]]
  404. function Slab.EndMenu()
  405. Menu.EndMenu()
  406. end
  407. --[[
  408. BeginContextMenuItem
  409. 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
  410. call to open up a context menu for that specific item. If this function returns true, EndContextMenu must be called.
  411. Example:
  412. if Slab.Button("Button!") then
  413. -- Perform logic here when button is clicked
  414. end
  415. -- This will only return true if the previous button is hot and the user right-clicks.
  416. if Slab.BeginContextMenuItem() then
  417. Slab.MenuItem("Button Item 1")
  418. Slab.MenuItem("Button Item 2")
  419. Slab.EndContextMenu()
  420. end
  421. Return: [Boolean] Returns true if the user right clicks on the previous item call. EndContextMenu must be called in order for
  422. this to function properly.
  423. --]]
  424. function Slab.BeginContextMenuItem()
  425. return Menu.BeginContextMenu({IsItem = true})
  426. end
  427. --[[
  428. BeginContextMenuWindow
  429. 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
  430. of a window's widget calls so that Slab can catch any BeginContextMenuItem calls before this call. If this function returns true,
  431. EndContextMenu must be called.
  432. Return: [Boolean] Returns true if the user right clicks anywhere within the window. EndContextMenu must be called in order for this
  433. to function properly.
  434. --]]
  435. function Slab.BeginContextMenuWindow()
  436. return Menu.BeginContextMenu({IsWindow = true})
  437. end
  438. --[[
  439. EndContextMenu
  440. Finishes up any BeginContextMenuItem/BeginContextMenuWindow if they return true.
  441. Return: None.
  442. --]]
  443. function Slab.EndContextMenu()
  444. Menu.EndContextMenu()
  445. end
  446. --[[
  447. MenuItem
  448. Adds a menu item to a given context menu.
  449. Label: [String] The label to display to the user.
  450. Return: [Boolean] Returns true if the user clicks on this menu item.
  451. --]]
  452. function Slab.MenuItem(Label)
  453. return Menu.MenuItem(Label)
  454. end
  455. --[[
  456. MenuItemChecked
  457. Adds a menu item to a given context menu. If IsChecked is true, then a check mark will be rendered next to the
  458. label.
  459. Example:
  460. local Checked = false
  461. if Slab.MenuItemChecked("Menu Item", Checked)
  462. Checked = not Checked
  463. end
  464. Label: [String] The label to display to the user.
  465. IsChecked: [Boolean] Determines if a check mark should be rendered next to the label.
  466. Return: [Boolean] Returns true if the user clicks on this menu item.
  467. --]]
  468. function Slab.MenuItemChecked(Label, IsChecked)
  469. return Menu.MenuItemChecked(Label, IsChecked)
  470. end
  471. --[[
  472. Separator
  473. This functions renders a separator line in the window.
  474. Option: [Table] List of options for how this separator will be drawn.
  475. IncludeBorders: [Boolean] Whether to extend the separator to include the window borders. This is false by default.
  476. H: [Number] The height of the separator. This doesn't change the line thickness, rather, specifies the cursor advancement
  477. in the Y direction.
  478. Return: None.
  479. --]]
  480. function Slab.Separator(Options)
  481. Separator.Begin(Options)
  482. end
  483. --[[
  484. Button
  485. Adds a button to the active window.
  486. Label: [String] The label to display on the button.
  487. Options: [Table] List of options for how this button will behave.
  488. Tooltip: [String] The tooltip to display when the user hovers over this button.
  489. AlignRight: [Boolean] Flag to push this button to the right side of the window.
  490. ExpandW: [Boolean] Expands the button to fit the contents of the window.
  491. Rounding: [Number] Amount of rounding to apply to the corners of the button.
  492. Invisible: [Boolean] Don't render the button, but keep the behavior.
  493. W: [Number] Override the width of the button.
  494. H: [Number] Override the height of the button.
  495. Disabled: [Boolean] If true, the button is not interactable by the user.
  496. Return: [Boolean] Returns true if the user clicks on this button.
  497. --]]
  498. function Slab.Button(Label, Options)
  499. return Button.Begin(Label, Options)
  500. end
  501. --[[
  502. RadioButton
  503. Adds a radio button entry to the active window. The grouping of radio buttons is determined by the user. An Index can
  504. be applied to the given radio button and a SelectedIndex can be passed in to determine if this specific radio button
  505. is the selected one.
  506. Label: [String] The label to display next to the button.
  507. Options: [Table] List of options for how this radio button will behave.
  508. Index: [Number] The index of this radio button. Will be 0 by default and not selectable. Assign an index to group the button.
  509. SelectedIndex: [Number] The index of the radio button that is selected. If this equals the Index field, then this radio button
  510. will be rendered as selected.
  511. Tooltip: [String] The tooltip to display when the user hovers over the button or label.
  512. Return: [Boolean] Returns true if the user clicks on this button.
  513. --]]
  514. function Slab.RadioButton(Label, Options)
  515. return Button.BeginRadio(Label, Options)
  516. end
  517. --[[
  518. Text
  519. Adds text to the active window.
  520. Label: [String] The string to be displayed in the window.
  521. Options: [Table] List of options for how this text is displayed.
  522. Color: [Table] The color to render the text.
  523. Pad: [Number] How far to pad the text from the left side of the current cursor position.
  524. IsSelectable: [Boolean] Whether this text is selectable using the text's Y position and the window X and width as the
  525. hot zone.
  526. IsSelectableTextOnly: [Boolean] Only available if IsSelectable is true. Will use the text width instead of the
  527. window width to determine the hot zone.
  528. IsSelected: [Boolean] Forces the hover background to be rendered.
  529. SelectOnHover: [Boolean] Returns true if the user is hovering over the hot zone of this text.
  530. HoverColor: [Table] The color to render the background if the IsSelected option is true.
  531. CenterX: [Boolean] Should the text be centered relative to the current active bounds.
  532. Return: [Boolean] Returns true if SelectOnHover option is set to true. False otherwise.
  533. --]]
  534. function Slab.Text(Label, Options)
  535. return Text.Begin(Label, Options)
  536. end
  537. --[[
  538. TextSelectable
  539. This function is a shortcut for SlabText with the IsSelectable option set to true.
  540. Label: [String] The string to be displayed in the window.
  541. Options: [Table] List of options for how this text is displayed.
  542. See Slab.Text for all options.
  543. Return: [Boolean] Returns true if user clicks on this text. False otherwise.
  544. --]]
  545. function Slab.TextSelectable(Label, Options)
  546. Options = Options == nil and {} or Options
  547. Options.IsSelectable = true
  548. return Slab.Text(Label, Options)
  549. end
  550. --[[
  551. Textf
  552. Adds formatted text to the active window. This text will wrap to fit within the contents of
  553. either the window or a user specified width.
  554. Label: [String] The text to be rendered.
  555. Options: [Table] List of options for how this text is displayed.
  556. Color: [Table] The color to render the text.
  557. W: [Number] The width to restrict the text to. If this option is not specified, then the window
  558. width is used.
  559. Align: [String] The alignment to use for this text. For more information, refer to the love documentation
  560. at https://love2d.org/wiki/AlignMode. Below are the available options:
  561. center: Align text center.
  562. left: Align text left.
  563. right: Align text right.
  564. justify: Align text both left and right.
  565. Return: None.
  566. --]]
  567. function Slab.Textf(Label, Options)
  568. Text.BeginFormatted(Label, Options)
  569. end
  570. --[[
  571. CheckBox
  572. Renders a check box with a label. The check box when enabled will render an 'X'.
  573. Enabled: [Boolean] Will render an 'X' within the box if true. Will be an empty box otherwise.
  574. Label: [String] The label to display after the check box.
  575. Options: [Table] List of options for how this check box will behave.
  576. Tooltip: [String] Text to be displayed if the user hovers over the check box.
  577. Id: [String] An optional Id that can be supplied by the user. By default, the Id will be the label.
  578. Rounding: [Number] Amount of rounding to apply to the corners of the check box.
  579. Return: [Boolean] Returns true if the user clicks within the check box.
  580. --]]
  581. function Slab.CheckBox(Enabled, Label, Options)
  582. return CheckBox.Begin(Enabled, Label, Options)
  583. end
  584. --[[
  585. Input
  586. This function will render an input box for a user to input text in. This widget behaves like input boxes
  587. found in other applications. This function will only return true if it has focus and user has either input
  588. text or pressed the return key.
  589. Example:
  590. local Text = "Hello World"
  591. if Slab.Input('Example', {Text = Text}) then
  592. Text = Slab.GetInputText()
  593. end
  594. Id: [String] A string that uniquely identifies this Input within the context of the window.
  595. Options: [Table] List of options for how this Input will behave.
  596. Tooltip: [String] Text to be displayed if the user hovers over the Input box.
  597. ReturnOnText: [Boolean] Will cause this function to return true whenever the user has input
  598. a new character into the Input box. This is true by default.
  599. Text: [String] The text to be supplied to the input box. It is recommended to use this option
  600. when ReturnOnText is true.
  601. BgColor: [Table] The background color for the input box.
  602. SelectColor: [Table] The color used when the user is selecting text within the input box.
  603. SelectOnFocus: [Boolean] When this input box is focused by the user, the text contents within the input
  604. will be selected. This is true by default.
  605. NumbersOnly: [Boolean] When true, only numeric characters and the '.' character are allowed to be input into
  606. the input box. If no text is input, the input box will display '0'.
  607. W: [Number] The width of the input box. By default, will be 150.0
  608. H: [Number] The height of the input box. By default, will be the height of the current font.
  609. ReadOnly: [Boolean] Whether this input field can be editable or not.
  610. Align: [String] Aligns the text within the input box. Options are:
  611. left: Aligns the text to the left. This will be set when this Input is focused.
  612. center: Aligns the text in the center. This is the default for when the text is not focused.
  613. Rounding: [Number] Amount of rounding to apply to the corners of the input box.
  614. MinNumber: [Number] The minimum value that can be entered into this input box. Only valid when NumbersOnly is true.
  615. MaxNumber: [Number] The maximum value that can be entered into this input box. Only valid when NumbersOnly is true.
  616. MultiLine: [Boolean] Determines whether this input control should support multiple lines. If this is true, then the
  617. SelectOnFocus flag will be false. The given text will also be sanitized to remove controls characters such as
  618. '\r'. Also, the text will be left aligned.
  619. MultiLineW: [Number] The width for which the lines of text should be wrapped at.
  620. Return: [Boolean] Returns true if the user has pressed the return key while focused on this input box. If ReturnOnText
  621. is set to true, then this function will return true whenever the user has input any character into the input box.
  622. --]]
  623. function Slab.Input(Id, Options)
  624. return Input.Begin(Id, Options)
  625. end
  626. --[[
  627. GetInputText
  628. Retrieves the text entered into the focused input box. Refer to the documentation for Slab.Input for an example on how to
  629. use this function.
  630. Return: [String] Returns the text entered into the focused input box.
  631. --]]
  632. function Slab.GetInputText()
  633. return Input.GetText()
  634. end
  635. --[[
  636. GetInputNumber
  637. Retrieves the text entered into the focused input box and attempts to conver the text into a number. Will always return a valid
  638. number.
  639. Return: [Number] Returns the text entered into the focused input box as a number.
  640. --]]
  641. function Slab.GetInputNumber()
  642. local Result = tonumber(Input.GetText())
  643. if Result == nil then
  644. Result = 0
  645. end
  646. return Result
  647. end
  648. --[[
  649. BeginTree
  650. This function will render a tree item with an optional label. The tree can be expanded or collapsed based on whether
  651. the user clicked on the tree item. This function can also be nested to create a hierarchy of tree items. This function
  652. will return false when collapsed and true when expanded. If this function returns true, Slab.EndTree must be called in
  653. 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
  654. of the window by default.
  655. Id: [String] A string uniquely identifying this tree item within the context of the window.
  656. Options: [Table] List of options for how this tree item will behave.
  657. Label: [String] The text to be rendered for this tree item.
  658. Tooltip: [String] The text to be rendered when the user hovers over this tree item.
  659. IsLeaf: [Boolean] If this is true, this tree item will not be expandable/collapsable.
  660. OpenWithHighlight: [Boolean] If this is true, the tree will be expanded/collapsed when the user hovers over the hot
  661. zone of this tree item. If this is false, the user must click the expand/collapse icon to interact with this tree
  662. item.
  663. Icon: [Object] A user supplied image. This must be a valid Love image or the call will assert.
  664. IconPath: [String] If the Icon option is nil, then a path can be specified. Slab will load and
  665. manage the image resource.
  666. IsSelected: [Boolean] If true, will render a highlight rectangle around the tree item.
  667. IsOpen: [Boolean] Will force the tree item to be expanded.
  668. Return: [Boolean] Returns true if this tree item is expanded. Slab.EndTree must be called if this returns true.
  669. --]]
  670. function Slab.BeginTree(Id, Options)
  671. return Tree.Begin(Id, Options)
  672. end
  673. --[[
  674. EndTree
  675. Finishes up any BeginTree calls if those functions return true.
  676. Return: None.
  677. --]]
  678. function Slab.EndTree()
  679. Tree.End()
  680. end
  681. --[[
  682. BeginComboBox
  683. This function renders a non-editable input field with a drop down arrow. When the user clicks this option, a window is
  684. created and the user can supply their own Slab.TextSelectable calls to add possible items to select from. This function
  685. will return true if the combo box is opened. Slab.EndComboBox must be called if this function returns true.
  686. Example:
  687. local Options = {"Apple", "Banana", "Orange", "Pear", "Lemon"}
  688. local Options_Selected = ""
  689. if Slab.BeginComboBox('Fruits', {Selected = Options_Selected}) then
  690. for K, V in pairs(Options) do
  691. if Slab.TextSelectable(V) then
  692. Options_Selected = V
  693. end
  694. end
  695. Slab.EndComboBox()
  696. end
  697. Id: [String] A string that uniquely identifies this combo box within the context of the active window.
  698. Options: [Table] List of options that control how this combo box behaves.
  699. Tooltip: [String] Text that is rendered when the user hovers over this combo box.
  700. Selected: [String] Text that is displayed in the non-editable input box for this combo box.
  701. W: [Number] The width of the combo box. The default value is 150.0.
  702. Rounding: [Number] Amount of rounding to apply to the corners of the combo box.
  703. Return: [Boolean] This function will return true if the combo box is open.
  704. --]]
  705. function Slab.BeginComboBox(Id, Options)
  706. return ComboBox.Begin(Id, Options)
  707. end
  708. --[[
  709. EndComboBox
  710. Finishes up any BeginComboBox calls if those functions return true.
  711. Return: None.
  712. --]]
  713. function Slab.EndComboBox()
  714. ComboBox.End()
  715. end
  716. --[[
  717. Image
  718. Draws an image at the current cursor position. The Id uniquely identifies this
  719. image to manage behaviors with this image. An image can be supplied through the
  720. options or a path can be specified which Slab will manage the loading and storing of
  721. the image reference.
  722. Id: [String] A string uniquely identifying this image within the context of the current window.
  723. Options: [Table] List of options controlling how the image should be drawn.
  724. Image: [Object] A user supplied image. This must be a valid Love image or the call will assert.
  725. Path: [String] If the Image option is nil, then a path must be specified. Slab will load and
  726. manage the image resource.
  727. Rotation: [Number] The rotation value to apply when this image is drawn.
  728. Scale: [Number] The scale value to apply to both the X and Y axis.
  729. ScaleX: [Number] The scale value to apply to the X axis.
  730. ScaleY: [Number] The scale value to apply to the Y axis.
  731. Color: [Table] The color to use when rendering this image.
  732. ReturnOnHover: [Boolean] Returns true when the mouse is hovered over the image.
  733. ReturnOnClick: [Boolean] Returns true when the mouse is released over the image.
  734. SubX: [Number] The X-coordinate used inside the given image.
  735. SubY: [Number] The Y-coordinate used inside the given image.
  736. SubW: [Number] The width used inside the given image.
  737. SubH: [Number] The height used insided the given image.
  738. WrapX: [String] The horizontal wrapping mode for this image. The available options are 'clamp', 'repeat',
  739. 'mirroredrepeat', and 'clampzero'. For more information refer to the Love2D documentation on wrap modes at
  740. https://love2d.org/wiki/WrapMode.
  741. WrapY: [String] The vertical wrapping mode for this image. The available options are 'clamp', 'repeat',
  742. 'mirroredrepeat', and 'clampzero'. For more information refer to the Love2D documentation on wrap modes at
  743. https://love2d.org/wiki/WrapMode.
  744. Return: [Boolean] Returns true if the mouse is hovering over the image or clicking on the image based on
  745. ReturnOnHover or ReturnOnClick options.
  746. --]]
  747. function Slab.Image(Id, Options)
  748. return Image.Begin(Id, Options)
  749. end
  750. --[[
  751. SameLine
  752. This forces the cursor to move back up to the same line as the previous widget. By default, all Slab widgets will
  753. advance the cursor to the next line based on the height of the current line. By using this call with other widget
  754. calls, the user will be able to set up multiple widgets on the same line to control how a window may look.
  755. Options: [Table] List of options that controls how the cursor should handle the same line.
  756. Pad: [Number] Extra padding to apply in the X direction.
  757. CenterY: [Boolean] Controls whether the cursor should be centered in the Y direction on the line. By default
  758. the line will use the NewLineSize, which is the height of the current font to center the cursor.
  759. Return: None.
  760. --]]
  761. function Slab.SameLine(Options)
  762. Cursor.SameLine(Options)
  763. end
  764. --[[
  765. NewLine
  766. This forces the cursor to advance to the next line based on the height of the current font.
  767. Return: None.
  768. --]]
  769. function Slab.NewLine()
  770. Cursor.NewLine()
  771. end
  772. --[[
  773. SetCursorPos
  774. Sets the cursor position. The default behavior is to set the cursor position relative to
  775. the current window. The absolute position can be set if the 'Absolute' option is set.
  776. Controls will only be drawn within a window. If the cursor is set outside of the current
  777. window context, the control will not be displayed.
  778. X: [Number] The X coordinate to place the cursor. If nil, then the X coordinate is not modified.
  779. Y: [Number] The Y coordinate to place the cursor. If nil, then the Y coordinate is not modified.
  780. Options: [Table] List of options that control how the cursor position should be set.
  781. Absolute: [Boolean] If true, will place the cursor using absolute coordinates.
  782. Return: None.
  783. --]]
  784. function Slab.SetCursorPos(X, Y, Options)
  785. Options = Options == nil and {} or Options
  786. Options.Absolute = Options.Absolute == nil and false or Options.Absolute
  787. if Options.Absolute then
  788. X = X == nil and Cursor.GetX() or X
  789. Y = Y == nil and Cursor.GetY() or Y
  790. Cursor.SetPosition(X, Y)
  791. else
  792. X = X == nil and Cursor.GetX() - Cursor.GetAnchorX() or X
  793. Y = Y == nil and Cursor.GetY() - Cursor.GetAnchorY() or Y
  794. Cursor.SetRelativePosition(X, Y)
  795. end
  796. end
  797. --[[
  798. GetCursorPos
  799. Gets the cursor position. The default behavior is to get the cursor position relative to
  800. the current window. The absolute position can be retrieved if the 'Absolute' option is set.
  801. Options: [Table] List of options that control how the cursor position should be retrieved.
  802. Absolute: [Boolean] If true, will return the cursor position in absolute coordinates.
  803. Return: [Number], [Number] The X and Y coordinates of the cursor.
  804. --]]
  805. function Slab.GetCursorPos(Options)
  806. Options = Options == nil and {} or Options
  807. Options.Absolute = Options.Absolute == nil and false or Options.Absolute
  808. local X, Y = Cursor.GetPosition()
  809. if not Options.Absolute then
  810. X = X - Cursor.GetAnchorX()
  811. Y = Y - Cursor.GetAnchorY()
  812. end
  813. return X, Y
  814. end
  815. --[[
  816. Properties
  817. Iterates through the table's key-value pairs and adds them to the active window. This currently only does
  818. a shallow loop and will not iterate through nested tables.
  819. TODO: Iterate through nested tables.
  820. Table: [Table] The list of properties to build widgets for.
  821. Return: None.
  822. --]]
  823. function Slab.Properties(Table)
  824. if Table ~= nil then
  825. for K, V in pairs(Table) do
  826. local Type = type(V)
  827. if Type == "boolean" then
  828. if Slab.CheckBox(V, K) then
  829. Table[K] = not Table[K]
  830. end
  831. elseif Type == "number" then
  832. Slab.Text(K .. ": ")
  833. Slab.SameLine()
  834. if Slab.Input(K, {Text = tostring(V), NumbersOnly = true, ReturnOnText = false}) then
  835. Table[K] = Slab.GetInputNumber()
  836. end
  837. elseif Type == "string" then
  838. Slab.Text(K .. ": ")
  839. Slab.SameLine()
  840. if Slab.Input(K, {Text = V, ReturnOnText = false}) then
  841. Table[K] = Slab.GetInputText()
  842. end
  843. end
  844. end
  845. end
  846. end
  847. --[[
  848. BeginListBox
  849. Begins the process of creating a list box. If this function is called, EndListBox must be called after all
  850. items have been added.
  851. Id: [String] A string uniquely identifying this list box within the context of the current window.
  852. Options: [Table] List of options controlling the behavior of the list box.
  853. W: [Number] The width of the list box. If nil, then the width of the window is used.
  854. H: [Number] The height of the list box. If nil, a default value of 150 is used. If H is 0, then
  855. the list box will stretch to the height of the window.
  856. Clear: [Boolean] Clears out the items in the list. It is recommended to only call this if the list items
  857. has changed and should not be set to true on every frame.
  858. Rounding: [Number] Amount of rounding to apply to the corners of the list box.
  859. Return: None.
  860. --]]
  861. function Slab.BeginListBox(Id, Options)
  862. ListBox.Begin(Id, Options)
  863. end
  864. --[[
  865. EndListBox
  866. Ends the list box container. Will close off the region and properly adjust the cursor.
  867. Return: None.
  868. --]]
  869. function Slab.EndListBox()
  870. ListBox.End()
  871. end
  872. --[[
  873. BeginListBoxItem
  874. Adds an item to the current list box with the given Id. The user can then draw controls however they see
  875. fit to display a single item. This allows the user to draw list items such as a texture with a name or just
  876. a text to represent the item. If this is called, EndListBoxItem must be called to complete the item.
  877. Id: [String] A string uniquely identifying this item within the context of the current list box.
  878. Options: [Table] List of options that control the behavior of the active list item.
  879. Selected: [Boolean] If true, will draw the item with a selection background.
  880. Return: None.
  881. --]]
  882. function Slab.BeginListBoxItem(Id, Options)
  883. ListBox.BeginItem(Id, Options)
  884. end
  885. --[[
  886. IsListBoxItemClicked
  887. Checks to see if a hot list item is clicked. This should only be called within a BeginListBoxLitem/EndListBoxItem
  888. block.
  889. Button: [Number] The button to check for the click of the item.
  890. IsDoubleClick: [Boolean] Check for double-click instead of single click.
  891. Return: [Boolean] Returns true if the active item is hovered with mouse and the requested mouse button is clicked.
  892. --]]
  893. function Slab.IsListBoxItemClicked(Button, IsDoubleClick)
  894. return ListBox.IsItemClicked(Button, IsDoubleClick)
  895. end
  896. --[[
  897. EndListBoxItem
  898. Ends the current item and commits the bounds of the item to the list.
  899. Return: None.
  900. --]]
  901. function Slab.EndListBoxItem()
  902. ListBox.EndItem()
  903. end
  904. --[[
  905. OpenDialog
  906. Opens the dialog box with the given Id. If the dialog box was opened, then it is pushed onto the stack.
  907. Calls to the BeginDialog with this same Id will return true if opened.
  908. Id: [String] A string uniquely identifying this dialog box.
  909. Return: None.
  910. --]]
  911. function Slab.OpenDialog(Id)
  912. Dialog.Open(Id)
  913. end
  914. --[[
  915. BeginDialog
  916. Begins the dialog window with the given Id if it is open. If this function returns true, then EndDialog must be called.
  917. Dialog boxes are windows which are centered in the center of the viewport. The dialog box cannot be moved and will
  918. capture all input from all other windows.
  919. Id: [String] A string uniquely identifying this dialog box.
  920. Options: [Table] List of options that control how this dialog box behaves. These are the same parameters found
  921. for BeginWindow, with some caveats. Certain options are overridden by the Dialog system. They are:
  922. X, Y, Layer, AllowFocus, AllowMove, and AutoSizeWindow.
  923. Return: [Boolean] Returns true if the dialog with the given Id is open.
  924. --]]
  925. function Slab.BeginDialog(Id, Options)
  926. return Dialog.Begin(Id, Options)
  927. end
  928. --[[
  929. EndDialog
  930. Ends the dialog window if a call to BeginDialog returns true.
  931. Return: None.
  932. --]]
  933. function Slab.EndDialog()
  934. Dialog.End()
  935. end
  936. --[[
  937. CloseDialog
  938. Closes the currently active dialog box.
  939. Return: None.
  940. --]]
  941. function Slab.CloseDialog()
  942. Dialog.Close()
  943. end
  944. --[[
  945. MessageBox
  946. Opens a message box to be displayed to the user with a title and a message. Buttons can be specified through the options
  947. table which when clicked, the string of the button is returned. This function should be called every frame when a message
  948. box wants to be displayed.
  949. Title: [String] The title to display for the message box.
  950. Message: [String] The message to be displayed. The text is aligned in the center. Multi-line strings are supported.
  951. Options: [Table] List of options to control the behavior of the message box.
  952. Buttons: [Table] List of buttons to display with the message box. The order of the buttons are displayed from right to left.
  953. Return: [String] The name of the button that was clicked. If none was clicked, an emtpy string is returned.
  954. --]]
  955. function Slab.MessageBox(Title, Message, Options)
  956. return Dialog.MessageBox(Title, Message, Options)
  957. end
  958. --[[
  959. FileDialog
  960. Opens up a dialog box that displays a file explorer for opening or saving files or directories. This function does not create any file
  961. handles, it just returns the list of files selected by the user.
  962. Options: [Table] List of options that control the behavior of the file dialog.
  963. AllowMultiSelect: [Boolean] Allows the user to select multiple items in the file dialog.
  964. Directory: [String] The starting directory when the file dialog is open. If none is specified, the dialog
  965. will start at love.filesystem.getSourceBaseDirectory and the dialog will remember the last
  966. directory navigated to by the user between calls to this function.
  967. Type: [String] The type of file dialog to use. The options are:
  968. openfile: This is the default method. The user will have access to both directories and files. However,
  969. only file selections are returned.
  970. opendirectory: This type is used to filter the file dialog for directories only. No files will appear
  971. in the list.
  972. savefile: This type is used to select a name of a file to save. The user will be prompted if they wish to overwrite
  973. an existing file.
  974. Filters: [Table] A list of filters the user can select from when browsing files. The table can contain tables or strings.
  975. Table: If a table is used for a filter, it should contain two elements. The first element is the filter while the second
  976. element is the description of the filter e.g. {"*.lua", "Lua Files"}
  977. String: If a raw string is used, then it should just be the filter. It is recommended to use the table option since a
  978. description can be given for each filter.
  979. Return: [Table] Returns items for how the user interacted with this file dialog.
  980. Button: [String] The button the user clicked. Will either be OK or Cancel.
  981. Files: [Table] An array of selected file items the user selected when OK is pressed. Will be empty otherwise.
  982. --]]
  983. function Slab.FileDialog(Options)
  984. return Dialog.FileDialog(Options)
  985. end
  986. --[[
  987. ColorPicker
  988. 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
  989. should be handled to stop displaying the color picker and store the resulting color.
  990. Options: [Table] List of options that control the behavior of the color picker.
  991. Color: [Table] The color to modify. This should be in the format of 0-1 for each color component (RGBA).
  992. Return: [Table] Returns the button and color the user has selected.
  993. Button: [String] The button the user clicked. Will either be OK or Cancel.
  994. Color: [Table] The new color the user has chosen. This will always be returned.
  995. --]]
  996. function Slab.ColorPicker(Options)
  997. return ColorPicker.Begin(Options)
  998. end
  999. --[[
  1000. IsMouseDown
  1001. Determines if a given mouse button is down.
  1002. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1003. Return: [Boolean] True if the given button is down. False otherwise.
  1004. --]]
  1005. function Slab.IsMouseDown(Button)
  1006. return Mouse.IsPressed(Button and Button or 1)
  1007. end
  1008. --[[
  1009. IsMouseClicked
  1010. Determines if a given mouse button changes state from up to down this frame.
  1011. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1012. Return: [Boolean] True if the given button changes state from up to down. False otherwise.
  1013. --]]
  1014. function Slab.IsMouseClicked(Button)
  1015. return Mouse.IsClicked(Button and Button or 1)
  1016. end
  1017. --[[
  1018. IsMouseReleased
  1019. Determines if a given mouse button changes state from down to up this frame.
  1020. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1021. Return: [Boolean] True if the given button changes state from down to up. False otherwise.
  1022. --]]
  1023. function Slab.IsMouseReleased(Button)
  1024. return Mouse.IsReleased(Button and Button or 1)
  1025. end
  1026. --[[
  1027. IsMouseDoubleClicked
  1028. Determines if a given mouse button has been clicked twice within a given time frame.
  1029. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1030. Return: [Boolean] True if the given button was double clicked. False otherwise.
  1031. --]]
  1032. function Slab.IsMouseDoubleClicked(Button)
  1033. return Mouse.IsDoubleClicked(Button and Button or 1)
  1034. end
  1035. --[[
  1036. IsMouseDragging
  1037. Determines if a given mouse button is down and there has been movement.
  1038. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1039. Return: [Boolean] True if the button is held down and is moving. False otherwise.
  1040. --]]
  1041. function Slab.IsMouseDragging(Button)
  1042. return Mouse.IsDragging(Button and Button or 1)
  1043. end
  1044. --[[
  1045. GetMousePosition
  1046. Retrieves the current mouse position in the viewport.
  1047. Return: [Number], [Number] The X and Y coordinates of the mouse position.
  1048. --]]
  1049. function Slab.GetMousePosition()
  1050. return Mouse.Position()
  1051. end
  1052. --[[
  1053. GetMouseDelta
  1054. Retrieves the change in mouse coordinates from the last frame.
  1055. Return: [Number], [Number] The X and Y coordinates of the delta from the last frame.
  1056. --]]
  1057. function Slab.GetMouseDelta()
  1058. return Mouse.GetDelta()
  1059. end
  1060. --[[
  1061. IsControlHovered
  1062. Checks to see if the last control added to the window is hovered by the mouse.
  1063. Return: [Boolean] True if the last control is hovered, false otherwise.
  1064. --]]
  1065. function Slab.IsControlHovered()
  1066. return Window.IsItemHot()
  1067. end
  1068. --[[
  1069. IsControlClicked
  1070. Checks to see if the previous control is hovered and clicked.
  1071. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1072. Return: [Boolean] True if the previous control is hovered and clicked. False otherwise.
  1073. --]]
  1074. function Slab.IsControlClicked(Button)
  1075. return Slab.IsControlHovered() and Slab.IsMouseClicked(Button)
  1076. end
  1077. --[[
  1078. IsVoidHovered
  1079. Checks to see if any non-Slab area of the viewport is hovered.
  1080. Return: [Boolean] True if any non-Slab area of the viewport is hovered. False otherwise.
  1081. --]]
  1082. function Slab.IsVoidHovered()
  1083. return Region.GetHotInstanceId() == '' and not Region.IsScrolling()
  1084. end
  1085. --[[
  1086. IsVoidClicked
  1087. Checks to see if any non-Slab area of the viewport is clicked.
  1088. Button: [Number] The button to check for. The valid numbers are: 1 - Left, 2 - Right, 3 - Middle.
  1089. Return: [Boolean] True if any non-Slab area of the viewport is clicked. False otherwise.
  1090. --]]
  1091. function Slab.IsVoidClicked(Button)
  1092. return Slab.IsMouseClicked(Button) and Slab.IsVoidHovered()
  1093. end
  1094. --[[
  1095. IsKeyDown
  1096. Checks to see if a specific key is held down. The key should be one of the love defined KeyConstant which the list can
  1097. be found at https://love2d.org/wiki/KeyConstant.
  1098. Key: [String] A love defined key constant.
  1099. Return: [Boolean] True if the key is held down. False otherwise.
  1100. --]]
  1101. function Slab.IsKeyDown(Key)
  1102. return Keyboard.IsDown(Key)
  1103. end
  1104. --[[
  1105. IsKeyPressed
  1106. 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
  1107. be found at https://love2d.org/wiki/KeyConstant.
  1108. Key: [String] A love defined key constant.
  1109. Return: [Boolean] True if the key state went from up to down this frame. False otherwise.
  1110. --]]
  1111. function Slab.IsKeyPressed(Key)
  1112. return Keyboard.IsPressed(Key, true)
  1113. end
  1114. --[[
  1115. IsKeyPressed
  1116. 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
  1117. be found at https://love2d.org/wiki/KeyConstant.
  1118. Key: [String] A love defined key constant.
  1119. Return: [Boolean] True if the key state went from down to up this frame. False otherwise.
  1120. --]]
  1121. function Slab.IsKeyReleased(Key)
  1122. return Keyboard.IsReleased(Key)
  1123. end
  1124. --[[
  1125. Rectangle
  1126. Draws a rectangle at the current cursor position for the active window.
  1127. Options: [Table] List of options that control how this rectangle is displayed.
  1128. Mode: [String] Whether this rectangle should be filled or outlines. The default value is 'fill'.
  1129. W: [Number] The width of the rectangle.
  1130. H: [Number] The height of the rectangle.
  1131. Color: [Table] The color to use for this rectangle.
  1132. Rounding: [Number] Amount of rounding to apply to each corner.
  1133. Outline: [Boolean] If the Mode option is 'fill', this option will allow an outline to be drawn.
  1134. OutlineColor: [Table] The color to use for the outline if requested.
  1135. Return: None.
  1136. --]]
  1137. function Slab.Rectangle(Options)
  1138. Shape.Rectangle(Options)
  1139. end
  1140. return Slab