SlabTest.lua 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092
  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. local Slab = require(SLAB_PATH .. '.Slab')
  21. local SlabDebug = require(SLAB_PATH .. '.SlabDebug')
  22. local SlabTest = {}
  23. local function DrawOverview()
  24. Slab.Textf(
  25. "Slab is an immediate mode GUI toolkit for the LÖVE 2D framework. This library " ..
  26. "is designed to allow users to easily add this library to their existing LÖVE 2D projects and " ..
  27. "quickly create tools to enable them to iterate on their ideas quickly. The user should be able " ..
  28. "to utilize this library with minimal integration steps and is completely written in Lua and utilizes " ..
  29. "the LÖVE 2D API. No compiled binaries are required and the user will have access to the source so " ..
  30. "that they may make adjustments that meet the needs of their own projects and tools. Refer to main.lua " ..
  31. "and SlabTest.lua for example usage of this library.\n\n" ..
  32. "This window will demonstrate the usage of the Slab library and give an overview of all the supported controls " ..
  33. "and features.")
  34. Slab.NewLine()
  35. Slab.Text("The current version of Slab is: ")
  36. Slab.SameLine()
  37. Slab.Text(Slab.GetVersion(), {Color = {0, 1, 0, 1}})
  38. Slab.Text("The current version of LÖVE is: ")
  39. Slab.SameLine()
  40. Slab.Text(Slab.GetLoveVersion(), {Color = {0, 1, 0, 1}})
  41. end
  42. local DrawButtons_NumClicked = 0
  43. local DrawButtons_NumClicked_Invisible = 0
  44. local DrawButtons_Enabled = false
  45. local DrawButtons_Hovered = false
  46. local function DrawButtons()
  47. Slab.Textf("Buttons are simple controls which respond to a user's left mouse click. Buttons will simply return true when they are clicked.")
  48. Slab.NewLine()
  49. if Slab.Button("Button") then
  50. DrawButtons_NumClicked = DrawButtons_NumClicked + 1
  51. end
  52. Slab.SameLine()
  53. Slab.Text("You have clicked this button " .. DrawButtons_NumClicked .. " time(s).")
  54. Slab.NewLine()
  55. Slab.Separator()
  56. Slab.Textf("Buttons can be tested for mouse hover with the call to Slab.IsControlHovered right after declaring the button.")
  57. Slab.Button(DrawButtons_Hovered and "Hovered" or "Not Hovered", {W = 100})
  58. DrawButtons_Hovered = Slab.IsControlHovered()
  59. Slab.NewLine()
  60. Slab.Separator()
  61. Slab.Textf("Buttons can have a custom width and height.")
  62. Slab.Button("Square", {W = 75, H = 75})
  63. Slab.NewLine()
  64. Slab.Separator()
  65. Slab.Textf(
  66. "Buttons can also be invisible. Below is a rectangle with an invisible button so that the designer can " ..
  67. "implement a custom button but still rely on the button behavior. Below is a custom rectangle drawn with an " ..
  68. "invisible button drawn at the same location.")
  69. local X, Y = Slab.GetCursorPos()
  70. Slab.Rectangle({Mode = 'line', W = 50.0, H = 50.0, Color = {1, 1, 1, 1}})
  71. Slab.SetCursorPos(X, Y)
  72. if Slab.Button("", {Invisible = true, W = 50.0, H = 50.0}) then
  73. DrawButtons_NumClicked_Invisible = DrawButtons_NumClicked_Invisible + 1
  74. end
  75. Slab.SameLine({CenterY = true})
  76. Slab.Text("Invisible button has been clicked " .. DrawButtons_NumClicked_Invisible .. " time(s).")
  77. Slab.NewLine()
  78. Slab.Separator()
  79. Slab.Textf("Buttons can also be disabled. Click the button below to toggle the status of the neighboring button.")
  80. if Slab.Button("Toggle") then
  81. DrawButtons_Enabled = not DrawButtons_Enabled
  82. end
  83. Slab.SameLine()
  84. Slab.Button(DrawButtons_Enabled and "Enabled" or "Disabled", {Disabled = not DrawButtons_Enabled})
  85. end
  86. local DrawText_Width = 450.0
  87. local DrawText_Alignment = {'left', 'center', 'right', 'justify'}
  88. local DrawText_Alignment_Selected = 'left'
  89. local DrawText_NumClicked = 0
  90. local DrawText_NumClicked_TextOnly = 0
  91. local function DrawText()
  92. Slab.Textf("Text controls displays text on the current window. Slab currently offers three ways to control the text.")
  93. Slab.NewLine()
  94. Slab.Separator()
  95. Slab.Text("The most basic text control is Slab.Text.")
  96. Slab.Text("The color of the text can be controlled with the 'Color' option.", {Color = {0, 1, 0, 1}})
  97. Slab.NewLine()
  98. Slab.Separator()
  99. Slab.Textf(
  100. "Text can be formatted using the Slab.Textf API. Formatted text will wrap the text based on the 'W' option. " ..
  101. "If the 'W' option is not specified, the window's width will be used as the width. Formatted text also has an " ..
  102. "alignment option.")
  103. Slab.NewLine()
  104. Slab.Text("Width")
  105. Slab.SameLine()
  106. if Slab.Input('DrawText_Width', {Text = tostring(DrawText_Width), NumbersOnly = true, ReturnOnText = false}) then
  107. DrawText_Width = Slab.GetInputNumber()
  108. end
  109. Slab.SameLine()
  110. Slab.Text("Alignment")
  111. Slab.SameLine()
  112. if Slab.BeginComboBox('DrawText_Alignment', {Selected = DrawText_Alignment_Selected}) then
  113. for I, V in ipairs(DrawText_Alignment) do
  114. if Slab.TextSelectable(V) then
  115. DrawText_Alignment_Selected = V
  116. end
  117. end
  118. Slab.EndComboBox()
  119. end
  120. Slab.Textf(
  121. "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore " ..
  122. "et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " ..
  123. "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " ..
  124. "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " ..
  125. "officia deserunt mollit anim id est laborum.", {W = DrawText_Width, Align = DrawText_Alignment_Selected})
  126. Slab.NewLine()
  127. Slab.Separator()
  128. Slab.Textf(
  129. "Text can also be interacted with using the Slab.TextSelectable function. A background will be " ..
  130. "rendered when the mouse is hovered over the text and the function will return true when clicked on. " ..
  131. "The selectable area expands to the width of the window by default. This can be changed to just the text " ..
  132. "with the 'IsSelectableTextOnly' option.")
  133. Slab.NewLine()
  134. if Slab.TextSelectable("This text has been clicked " .. DrawText_NumClicked .. " time(s).") then
  135. DrawText_NumClicked = DrawText_NumClicked + 1
  136. end
  137. Slab.NewLine()
  138. if Slab.TextSelectable("This text has been clicked " .. DrawText_NumClicked_TextOnly .. " time(s).", {IsSelectableTextOnly = true}) then
  139. DrawText_NumClicked_TextOnly = DrawText_NumClicked_TextOnly + 1
  140. end
  141. end
  142. local DrawCheckBox_Checked = false
  143. local DrawCheckBox_Checked_NoLabel = false
  144. local function DrawCheckBox()
  145. Slab.Textf(
  146. "Check boxes are controls that will display an empty box with an optional label. The function will " ..
  147. "return true if the user has clicked on the box. The code is then responsible for updating the checked " ..
  148. "flag to be passed back into the function.")
  149. Slab.NewLine()
  150. if Slab.CheckBox(DrawCheckBox_Checked, "Check Box") then
  151. DrawCheckBox_Checked = not DrawCheckBox_Checked
  152. end
  153. Slab.NewLine()
  154. Slab.Text("A check box with no label.")
  155. if Slab.CheckBox(DrawCheckBox_Checked_NoLabel) then
  156. DrawCheckBox_Checked_NoLabel = not DrawCheckBox_Checked_NoLabel
  157. end
  158. end
  159. local DrawRadioButton_Selected = 1
  160. local function DrawRadioButton()
  161. Slab.Textf("Radio buttons offer the user to select one option from a list of options.")
  162. Slab.NewLine()
  163. for I = 1, 5, 1 do
  164. if Slab.RadioButton("Option " .. I, {Index = I, SelectedIndex = DrawRadioButton_Selected}) then
  165. DrawRadioButton_Selected = I
  166. end
  167. end
  168. end
  169. local DrawMenus_Window_Selected = "Right click and select an option."
  170. local DrawMenus_Control_Selected = "Right click and select an option from a control."
  171. local DrawMenus_CheckBox = false
  172. local DrawMenus_ComboBox = {"Apple", "Banana", "Pear", "Orange", "Lemon"}
  173. local DrawMenus_ComboBox_Selected = "Apple"
  174. local function DrawContextMenuItem(Label)
  175. if Slab.BeginContextMenuItem() then
  176. for I = 1, 5, 1 do
  177. local MenuLabel = Label .. " Option " .. I
  178. if Slab.MenuItem(MenuLabel) then
  179. DrawMenus_Control_Selected = MenuLabel
  180. end
  181. end
  182. Slab.EndContextMenu()
  183. end
  184. end
  185. local function DrawMenus()
  186. Slab.Textf(
  187. "Menus are windows that allow users to make a selection from a list of items. " ..
  188. "Below are descriptions of the various menus and how they can be utilized.")
  189. Slab.NewLine()
  190. Slab.Separator()
  191. Slab.Textf(
  192. "The main menu bar is rendered at the top of the window with menu items being added " ..
  193. "from left to right. When a menu item is clicked, a context menu is opened below the " ..
  194. "selected item. Creating the main menu bar can open anywhere in the code after the " ..
  195. "Slab.Update call. These functions should not be called within a BeginWindow/EndWindow " ..
  196. "call.")
  197. Slab.NewLine()
  198. Slab.Separator()
  199. Slab.Textf(
  200. "Context menus are menus which are rendered above all other controls to allow the user to make a selection " ..
  201. "out of a list of items. These can be opened up through the menu bar, or through a right-click " ..
  202. "action from the user on a given window or control. Menus and menu items make up the context menu " ..
  203. "and menus can be nested to allow a tree options to be displayed.")
  204. Slab.NewLine()
  205. Slab.Textf(
  206. "Controls can have their own context menus. Right-click on each control to open up the menu " ..
  207. "and select an option.")
  208. Slab.NewLine()
  209. Slab.Text(DrawMenus_Control_Selected)
  210. Slab.NewLine()
  211. Slab.Button("Button")
  212. DrawContextMenuItem("Button")
  213. Slab.Text("Text")
  214. DrawContextMenuItem("Text")
  215. if Slab.CheckBox(DrawMenus_CheckBox, "Check Box") then
  216. DrawMenus_CheckBox = not DrawMenus_CheckBox
  217. end
  218. DrawContextMenuItem("Check Box")
  219. Slab.Input('DrawMenus_Input')
  220. DrawContextMenuItem("Input")
  221. if Slab.BeginComboBox('DrawMenus_ComboBox', {Selected = DrawMenus_ComboBox_Selected}) then
  222. for I, V in ipairs(DrawMenus_ComboBox) do
  223. if Slab.TextSelectable(V) then
  224. DrawMenus_Window_Selected = V
  225. end
  226. end
  227. Slab.EndComboBox()
  228. end
  229. DrawContextMenuItem("Combo Box")
  230. Slab.NewLine()
  231. Slab.Separator()
  232. Slab.Textf(
  233. "Right-clicking anywhere within this window will open up a context menu. Note that BeginContextMenuWindow " ..
  234. "must come after all BeginContextMenuItem calls.")
  235. Slab.NewLine()
  236. Slab.Textf(DrawMenus_Window_Selected)
  237. if Slab.BeginContextMenuWindow() then
  238. if Slab.BeginMenu("Window Menu 1") then
  239. for I = 1, 5, 1 do
  240. if Slab.MenuItem("Sub Window Option " .. I) then
  241. DrawMenus_Window_Selected = "Sub Window Option " .. I .. " selected."
  242. end
  243. end
  244. Slab.EndMenu()
  245. end
  246. for I = 1, 5, 1 do
  247. if Slab.MenuItem("Window Option " .. I) then
  248. DrawMenus_Window_Selected = "Window Option " .. I .. " selected."
  249. end
  250. end
  251. Slab.EndContextMenu()
  252. end
  253. end
  254. local DrawComboBox_Options = {"England", "France", "Germany", "USA", "Canada", "Mexico", "Japan", "South Korea", "China", "Russia", "India"}
  255. local DrawComboBox_Selected = "USA"
  256. local DrawComboBox_Selected_Width = "USA"
  257. local function DrawComboBox()
  258. Slab.Textf(
  259. "A combo box allows the user to select a single item from a list and display the selected item " ..
  260. "in the combo box. The list is only visible when the user is interacting with the control.")
  261. Slab.NewLine()
  262. if Slab.BeginComboBox('DrawComboBox_One', {Selected = DrawComboBox_Selected}) then
  263. for I, V in ipairs(DrawComboBox_Options) do
  264. if Slab.TextSelectable(V) then
  265. DrawComboBox_Selected = V
  266. end
  267. end
  268. Slab.EndComboBox()
  269. end
  270. Slab.NewLine()
  271. Slab.Separator()
  272. Slab.Textf("A combo box's width can be modified with the 'W' option.")
  273. Slab.NewLine()
  274. local W, H = Slab.GetWindowActiveSize()
  275. if Slab.BeginComboBox('DrawComboBox_Two', {Selected = DrawComboBox_Selected_Width, W = W}) then
  276. for I, V in ipairs(DrawComboBox_Options) do
  277. if Slab.TextSelectable(V) then
  278. DrawComboBox_Selected_Width = V
  279. end
  280. end
  281. Slab.EndComboBox()
  282. end
  283. end
  284. local DrawInput_Basic = "Hello World"
  285. local DrawInput_Basic_Return = "Hello World"
  286. local DrawInput_Basic_Numbers = 0
  287. local DrawInput_Basic_Numbers_Clamped = 0.5
  288. local DrawInput_MultiLine =
  289. [[
  290. function Foo()
  291. print("Bar")
  292. end
  293. The quick brown fox jumped over the lazy dog.]]
  294. local DrawInput_MultiLine_Width = math.huge
  295. local DrawInput_CursorPos = 0
  296. local DrawInput_CursorColumn = 0
  297. local DrawInput_CursorLine = 0
  298. local DrawInput_Highlight_Text =
  299. [[
  300. function Hello()
  301. print("World")
  302. end]]
  303. local DrawInput_Highlight_Table = {
  304. ['function'] = {1, 0, 0, 1},
  305. ['end'] = {0, 0, 1, 1}
  306. }
  307. local DrawInput_Highlight_Table_Modify = nil
  308. local function DrawInput()
  309. Slab.Textf(
  310. "The input control allows the user to enter in text into an input box. This control is similar " ..
  311. "to input boxes found in other applications. These controls are set up to handle UTF8 characters.")
  312. Slab.NewLine()
  313. Slab.Textf(
  314. "The first example is very simple. An Input control is declared and the resulting text is captured if " ..
  315. "the function returns true. By default, the function will return true on any text that is entered.")
  316. if Slab.Input('DrawInput_Basic', {Text = DrawInput_Basic}) then
  317. DrawInput_Basic = Slab.GetInputText()
  318. end
  319. Slab.NewLine()
  320. Slab.Textf(
  321. "The return behavior can be modified so that the function will only return true if the Enter/Return " ..
  322. "key is pressed. If the control loses focus without the Enter/Return key pressed, then the text will " ..
  323. "revert back to what it was before.")
  324. if Slab.Input('DrawInput_Basic_Return', {Text = DrawInput_Basic_Return, ReturnOnText = false}) then
  325. DrawInput_Basic_Return = Slab.GetInputText()
  326. end
  327. Slab.NewLine()
  328. Slab.Separator()
  329. Slab.Textf("Input controls can be configured to only take numeric values.")
  330. if Slab.Input('DrawInput_Basic_Numbers', {Text = tostring(DrawInput_Basic_Numbers), NumbersOnly = true}) then
  331. DrawInput_Basic_Numbers = Slab.GetInputNumber()
  332. end
  333. Slab.NewLine()
  334. Slab.Textf(
  335. "These numeric controls can also have min and/or max values set. Below is an example where the " ..
  336. "numeric input control is clamped from 0.0 to 1.0.")
  337. if Slab.Input('DrawInput_Basic_Numbers_Clamped', {Text = tostring(DrawInput_Basic_Numbers_Clamped), NumbersOnly = true, MinNumber = 0.0, MaxNumber = 1.0}) then
  338. DrawInput_Basic_Numbers_Clamped = Slab.GetInputNumber()
  339. end
  340. Slab.NewLine()
  341. Slab.Separator()
  342. Slab.Textf(
  343. "Input controls also allow for multi-line editing using the MultiLine option. The default text wrapping " ..
  344. "option is set to math.huge, but this can be modified with the MultiLineW option. The example below demonstrates " ..
  345. "how to set up a multi-line input control and shows how the size of the control can be modified.")
  346. Slab.NewLine()
  347. Slab.Text("MultiLineW")
  348. Slab.SameLine()
  349. if Slab.Input('DrawInput_MultiLine_Width', {Text = tostring(DrawInput_MultiLine_Width), NumbersOnly = true, ReturnOnText = false}) then
  350. DrawInput_MultiLine_Width = Slab.GetInputNumber()
  351. end
  352. Slab.SameLine()
  353. Slab.Text("Cursor Pos")
  354. Slab.SameLine()
  355. if Slab.Input('DrawInput_CursorPos', {Text = tostring(DrawInput_CursorPos), NumbersOnly = true, ReturnOnText = false, MinNumber = 0, W = 75}) then
  356. DrawInput_CursorPos = Slab.GetInputNumber()
  357. Slab.SetInputFocus('DrawInput_MultiLine')
  358. Slab.SetInputCursorPos(DrawInput_CursorPos)
  359. end
  360. Slab.SameLine()
  361. Slab.Text("Column")
  362. Slab.SameLine()
  363. if Slab.Input('DrawInput_CursorColumn', {Text = tostring(DrawInput_CursorColumn), NumbersOnly = true, ReturnOnText = false, MinNumber = 0, W = 75}) then
  364. DrawInput_CursorColumn = Slab.GetInputNumber()
  365. Slab.SetInputFocus('DrawInput_MultiLine')
  366. Slab.SetInputCursorPosLine(DrawInput_CursorColumn, DrawInput_CursorLine)
  367. end
  368. Slab.SameLine()
  369. Slab.Text("Line")
  370. Slab.SameLine()
  371. if Slab.Input('DrawInput_CursorLine', {Text = tostring(DrawInput_CursorLine), NumbersOnly = true, ReturnOnText = false, MinNumber = 0, W = 75}) then
  372. DrawInput_CursorLine = Slab.GetInputNumber()
  373. Slab.SetInputFocus('DrawInput_MultiLine')
  374. Slab.SetInputCursorPosLine(DrawInput_CursorColumn, DrawInput_CursorLine)
  375. end
  376. local W, H = Slab.GetWindowActiveSize()
  377. if Slab.Input('DrawInput_MultiLine', {Text = DrawInput_MultiLine, MultiLine = true, MultiLineW = DrawInput_MultiLine_Width, W = W, H = 150.0}) then
  378. DrawInput_MultiLine = Slab.GetInputText()
  379. end
  380. if Slab.IsInputFocused('DrawInput_MultiLine') then
  381. DrawInput_CursorPos, DrawInput_CursorColumn, DrawInput_CursorLine = Slab.GetInputCursorPos()
  382. end
  383. Slab.NewLine()
  384. Slab.Separator()
  385. Slab.Textf(
  386. "The input control also offers a way to highlight certain words with a custom color. Below is a list of keywords and the color used to define the word.")
  387. Slab.NewLine()
  388. local TextW, TextH = Slab.GetTextSize("")
  389. for K, V in pairs(DrawInput_Highlight_Table) do
  390. if Slab.Input('DrawInput_Highlight_Table_' .. K, {Text = K, ReturnOnText = false}) then
  391. DrawInput_Highlight_Table[K] = nil
  392. K = Slab.GetInputText()
  393. DrawInput_Highlight_Table[K] = V
  394. end
  395. Slab.SameLine({Pad = 20.0})
  396. Slab.Rectangle({W = 50, H = TextH, Color = V})
  397. if Slab.IsControlClicked() then
  398. DrawInput_Highlight_Table_Modify = K
  399. end
  400. Slab.SameLine({Pad = 20.0})
  401. if Slab.Button("Delete", {H = TextH}) then
  402. DrawInput_Highlight_Table[K] = nil
  403. end
  404. end
  405. if Slab.Button("Add") then
  406. DrawInput_Highlight_Table['new'] = {1, 0, 0, 1}
  407. end
  408. if DrawInput_Highlight_Table_Modify ~= nil then
  409. local Result = Slab.ColorPicker({Color = DrawInput_Highlight_Table[DrawInput_Highlight_Table_Modify]})
  410. if Result.Button ~= "" then
  411. if Result.Button == "OK" then
  412. DrawInput_Highlight_Table[DrawInput_Highlight_Table_Modify] = Result.Color
  413. end
  414. DrawInput_Highlight_Table_Modify = nil
  415. end
  416. end
  417. Slab.NewLine()
  418. if Slab.Input('DrawInput_Highlight', {Text = DrawInput_Highlight_Text, MultiLine = true, Highlight = DrawInput_Highlight_Table, W = W, H = 150.0}) then
  419. DrawInput_Highlight_Text = Slab.GetInputText()
  420. end
  421. end
  422. local DrawImage_Path = string.gsub(SLAB_PATH, "%.", "/") .. "/Internal/Resources/Textures/power.png"
  423. local DrawImage_Path_Icons = string.gsub(SLAB_PATH, "%.", "/") .. "/Internal/Resources/Textures/gameicons.png"
  424. local DrawImage_Color = {1, 0, 0, 1}
  425. local DrawImage_Color_Edit = false
  426. local DrawImage_Scale = 1.0
  427. local DrawImage_Scale_X = 1.0
  428. local DrawImage_Scale_Y = 1.0
  429. local DrawImage_Power = false
  430. local DrawImage_Power_Hovered = false
  431. local DrawImage_Power_On = {0, 1, 0, 1}
  432. local DrawImage_Power_Off = {1, 0, 0, 1}
  433. local DrawImage_Icon_X = 0
  434. local DrawImage_Icon_Y = 0
  435. local DrawImage_Icon_Move = false
  436. local function DrawImage()
  437. Slab.Textf(
  438. "Images can be drawn within windows and react to user interaction. A path to an image can be specified through the options of " ..
  439. "the Image function. If this is done, Slab will manage the image resource and will use the path as a key to the resource.")
  440. Slab.Image('DrawImage_Basic', {Path = DrawImage_Path})
  441. Slab.NewLine()
  442. Slab.Separator()
  443. Slab.Textf(
  444. "An image's color can be modified with the 'Color' option.")
  445. if Slab.Button("Change Color") then
  446. DrawImage_Color_Edit = true
  447. end
  448. if DrawImage_Color_Edit then
  449. local Result = Slab.ColorPicker({Color = DrawImage_Color})
  450. if Result.Button ~= "" then
  451. DrawImage_Color_Edit = false
  452. if Result.Button == "OK" then
  453. DrawImage_Color = Result.Color
  454. end
  455. end
  456. end
  457. Slab.Image('DrawImage_Color', {Path = DrawImage_Path, Color = DrawImage_Color})
  458. Slab.NewLine()
  459. Slab.Separator()
  460. Slab.Textf(
  461. "There is an option to modify the scale of an image. The scale can both be affected " ..
  462. "on the X or Y axis.")
  463. Slab.Text("Scale")
  464. Slab.SameLine()
  465. if Slab.Input('DrawImage_Scale', {Text = tostring(DrawImage_Scale), NumbersOnly = true, ReturnOnText = false, W = 75}) then
  466. DrawImage_Scale = Slab.GetInputNumber()
  467. DrawImage_Scale_X = DrawImage_Scale
  468. DrawImage_Scale_Y = DrawImage_Scale
  469. end
  470. Slab.SameLine({Pad = 6.0})
  471. Slab.Text("Scale X")
  472. Slab.SameLine()
  473. if Slab.Input('DrawImage_Scale_X', {Text = tostring(DrawImage_Scale_X), NumbersOnly = true, ReturnOnText = false, W = 75}) then
  474. DrawImage_Scale_X = Slab.GetInputNumber()
  475. end
  476. Slab.SameLine({Pad = 6.0})
  477. Slab.Text("Scale Y")
  478. Slab.SameLine()
  479. if Slab.Input('DrawImage_Scale_Y', {Text = tostring(DrawImage_Scale_Y), NumbersOnly = true, ReturnOnText = false, W = 75}) then
  480. DrawImage_Scale_Y = Slab.GetInputNumber()
  481. end
  482. Slab.Image('DrawImage_Scale', {Path = DrawImage_Path, ScaleX = DrawImage_Scale_X, ScaleY = DrawImage_Scale_Y})
  483. Slab.NewLine()
  484. Slab.Separator()
  485. Slab.Textf(
  486. "Images can also have interactions through the control API. The left image will change when the mouse is hovered " ..
  487. "while the right image will change on click.")
  488. Slab.Image('DrawImage_Hover', {Path = DrawImage_Path, Color = DrawImage_Power_Hovered and DrawImage_Power_On or DrawImage_Power_Off})
  489. DrawImage_Power_Hovered = Slab.IsControlHovered()
  490. Slab.SameLine({Pad = 12.0})
  491. Slab.Image('DrawImage_Click', {Path = DrawImage_Path, Color = DrawImage_Power and DrawImage_Power_On or DrawImage_Power_Off})
  492. if Slab.IsControlClicked() then
  493. DrawImage_Power = not DrawImage_Power
  494. end
  495. Slab.NewLine()
  496. Slab.Separator()
  497. Slab.Textf(
  498. "A sub region can be defined to draw a section of an image. Move the rectangle around and observe the image on the right.")
  499. local X, Y = Slab.GetCursorPos()
  500. local AbsX, AbsY = Slab.GetCursorPos({Absolute = true})
  501. Slab.Image('DrawImage_Icons', {Path = DrawImage_Path_Icons})
  502. if Slab.IsControlClicked() then
  503. local MouseX, MouseY = Slab.GetMousePositionWindow()
  504. local Left = AbsX + DrawImage_Icon_X
  505. local Right = Left + 50.0
  506. local Top = AbsY + DrawImage_Icon_Y
  507. local Bottom = Top + 50.0
  508. if Left <= MouseX and MouseX <= Right and
  509. Top <= MouseY and MouseY <= Bottom then
  510. DrawImage_Icon_Move = true
  511. end
  512. end
  513. if Slab.IsMouseReleased() then
  514. DrawImage_Icon_Move = false
  515. end
  516. local W, H = Slab.GetControlSize()
  517. if DrawImage_Icon_Move then
  518. local DeltaX, DeltaY = Slab.GetMouseDelta()
  519. DrawImage_Icon_X = math.max(DrawImage_Icon_X + DeltaX, 0.0)
  520. DrawImage_Icon_X = math.min(DrawImage_Icon_X, W - 50.0)
  521. DrawImage_Icon_Y = math.max(DrawImage_Icon_Y + DeltaY, 0.0)
  522. DrawImage_Icon_Y = math.min(DrawImage_Icon_Y, H - 50.0)
  523. end
  524. Slab.SetCursorPos(X + DrawImage_Icon_X, Y + DrawImage_Icon_Y)
  525. Slab.Rectangle({Mode = 'line', Color = {0, 0, 0, 1}, W = 50.0, H = 50.0})
  526. Slab.SetCursorPos(X + W + 12.0, Y)
  527. Slab.Image('DrawImage_Icons_Region', {
  528. Path = DrawImage_Path_Icons,
  529. SubX = DrawImage_Icon_X,
  530. SubY = DrawImage_Icon_Y,
  531. SubW = 50.0,
  532. SubH = 50.0
  533. })
  534. end
  535. local DrawCursor_NewLines = 1
  536. local DrawCursor_SameLinePad = 4.0
  537. local DrawCursor_X = nil
  538. local DrawCursor_Y = nil
  539. local function DrawCursor()
  540. Slab.Textf(
  541. "Slab offers a way to manage the drawing of controls through the cursor. Whenever a control is used, the cursor is "..
  542. "automatically advanced based on the size of the control. By default, cursors are advanced vertically downward based " ..
  543. "on the control's height. However, functions are provided to move the cursor back up to the previous line or create " ..
  544. "an empty line to advance the cursor downward.")
  545. for I = 1, DrawCursor_NewLines, 1 do
  546. Slab.NewLine()
  547. end
  548. Slab.Textf(
  549. "There is a new line between this text and the above description. Modify the number of new lines using the " ..
  550. "input box below.")
  551. if Slab.Input('DrawCursor_NewLines', {Text = tostring(DrawCursor_NewLines), NumbersOnly = true, ReturnOnText = false, MinNumber = 0}) then
  552. DrawCursor_NewLines = Slab.GetInputNumber()
  553. end
  554. Slab.NewLine()
  555. Slab.Separator()
  556. Slab.Textf(
  557. "Using the SameLine function, controls can be layed out on a single line with additional padding. Below are two buttons on " ..
  558. "the same line with some padding. Use the input field below to modify the padding.")
  559. Slab.Button("One")
  560. Slab.SameLine({Pad = DrawCursor_SameLinePad})
  561. Slab.Button("Two")
  562. if Slab.Input('DrawCursor_SameLinePad', {Text = tostring(DrawCursor_SameLinePad), NumbersOnly = true, ReturnOnText = false}) then
  563. DrawCursor_SameLinePad = Slab.GetInputNumber()
  564. end
  565. Slab.NewLine()
  566. Slab.Textf(
  567. "The SameLine function can also vertically center the next item based on the previous control. This is useful for labeling " ..
  568. "items that are much bigger than the text such as images.")
  569. Slab.Image('DrawCursor_Image', {Path = DrawImage_Path})
  570. Slab.SameLine({CenterY = true})
  571. Slab.Text("This text is centered with respect to the previous image.")
  572. Slab.NewLine()
  573. Slab.Separator()
  574. Slab.Textf(
  575. "Slab offers functions to retrieve and set the cursor position. The GetCursorPos function will return the cursor position " ..
  576. "relative to the current window. An option can be passed to retrieve the absolute position of the cursor with respect " ..
  577. "to the viewport.")
  578. local X, Y = Slab.GetCursorPos()
  579. Slab.Text("Cursor X: " .. X)
  580. Slab.SameLine()
  581. Slab.Text("Cursor Y: " .. Y)
  582. local AbsX, AbsY = Slab.GetCursorPos({Absolute = true})
  583. Slab.Text("Absolute X: " .. AbsX)
  584. Slab.SameLine()
  585. Slab.Text("Absolute Y: " .. AbsY)
  586. if DrawCursor_X == nil then
  587. DrawCursor_X, DrawCursor_Y = Slab.GetCursorPos()
  588. end
  589. if Slab.Input('DrawCursor_X', {Text = tostring(DrawCursor_X), NumbersOnly = true, ReturnOnText = false}) then
  590. DrawCursor_X = Slab.GetInputNumber()
  591. end
  592. Slab.SameLine()
  593. if Slab.Input('DrawCursor_Y', {Text = tostring(DrawCursor_Y), NumbersOnly = true, ReturnOnText = false}) then
  594. DrawCursor_Y = Slab.GetInputNumber()
  595. end
  596. Slab.SetCursorPos(DrawCursor_X, DrawCursor_Y + 30.0)
  597. Slab.Text("Use the input fields to move this text.")
  598. end
  599. local DrawListBox_Basic_Selected = 1
  600. local DrawListBox_Advanced_Selected = 1
  601. local function DrawListBox()
  602. Slab.Textf(
  603. "A list box is a scrollable region that contains a list of elements that a user can interact with. The API is flexible " ..
  604. "so that each element in the list can be rendered in any way desired. Below are a few examples on different ways a list " ..
  605. "box can be used.")
  606. Slab.NewLine()
  607. Slab.BeginListBox('DrawListBox_Basic')
  608. for I = 1, 10, 1 do
  609. Slab.BeginListBoxItem('DrawListBox_Basic_Item_' .. I, {Selected = I == DrawListBox_Basic_Selected})
  610. Slab.Text("List Box Item " .. I)
  611. if Slab.IsListBoxItemClicked() then
  612. DrawListBox_Basic_Selected = I
  613. end
  614. Slab.EndListBoxItem()
  615. end
  616. Slab.EndListBox()
  617. Slab.NewLine()
  618. Slab.Separator()
  619. Slab.Textf(
  620. "Each list box can contain more than just text. Below is an example of list items with a triangle and a label.")
  621. Slab.NewLine()
  622. Slab.BeginListBox('DrawListBox_Advanced')
  623. local Rotation = 0
  624. for I = 1, 4, 1 do
  625. Slab.BeginListBoxItem('DrawListBox_Advanced_Item_' .. I, {Selected = I == DrawListBox_Advanced_Selected})
  626. Slab.Triangle({Radius = 24.0, Rotation = Rotation})
  627. Slab.SameLine({CenterY = true})
  628. Slab.Text("Triangle " .. I)
  629. if Slab.IsListBoxItemClicked() then
  630. DrawListBox_Advanced_Selected = I
  631. end
  632. Slab.EndListBoxItem()
  633. Rotation = Rotation + 90
  634. end
  635. Slab.EndListBox()
  636. end
  637. local DrawTree_Icon_Path = SLAB_PATH .. "/Internal/Resources/Textures/Folder.png"
  638. local DrawTree_Opened_Selected = 1
  639. local function DrawTree()
  640. Slab.Textf(
  641. "Trees allow data to be viewed in a hierarchy. Trees can also contain leaf nodes which have no children.")
  642. Slab.NewLine()
  643. if Slab.BeginTree('DrawTree_Root', {Label = "Root"}) then
  644. if Slab.BeginTree('DrawTree_Child_1', {Label = "Child 1"}) then
  645. Slab.BeginTree('DrawTree_Child_1_Leaf_1', {Label = "Leaf 1", IsLeaf = true})
  646. Slab.EndTree()
  647. end
  648. Slab.BeginTree('DrawTree_Leaf_1', {Label = "Leaf 2", IsLeaf = true})
  649. Slab.EndTree()
  650. end
  651. Slab.NewLine()
  652. Slab.Separator()
  653. Slab.Textf(
  654. "The hot zone of a tree item starts at the expander and extends to the width of the window's content. " ..
  655. "This can be configured to only allow the tree item to be opened/closed with the expander.")
  656. Slab.NewLine()
  657. if Slab.BeginTree('DrawTree_Root_NoHighlight', {Label = "Root", OpenWithHighlight = false}) then
  658. Slab.BeginTree('DrawTree_Leaf', {Label = "Leaf", IsLeaf = true})
  659. Slab.EndTree()
  660. end
  661. Slab.NewLine()
  662. Slab.Separator()
  663. Slab.Textf(
  664. "Tree items can have an icon associated with them. A loaded Image object or path to an image can be " ..
  665. "specified.")
  666. Slab.NewLine()
  667. if Slab.BeginTree('DrawTree_Root_Icon', {Label = "Folder", IconPath = DrawTree_Icon_Path}) then
  668. Slab.BeginTree('DrawTree_Item_1', {Label = "Item 1", IsLeaf = true})
  669. Slab.BeginTree('DrawTree_Item_2', {Label = "Item 2", IsLeaf = true})
  670. if Slab.BeginTree('DrawTree_Child_1', {Label = "Folder", IconPath = DrawTree_Icon_Path}) then
  671. Slab.BeginTree('DrawTree_Item_3', {Label = "Item 3", IsLeaf = true})
  672. Slab.BeginTree('DrawTree_Item_4', {Label = "Item 4", IsLeaf = true})
  673. Slab.EndTree()
  674. end
  675. Slab.EndTree()
  676. end
  677. Slab.NewLine()
  678. Slab.Separator()
  679. Slab.Textf(
  680. "A tree item can be specified to be forced open with the IsOpen option as shown in the example below. The example " ..
  681. "also shows how tree items can have the selection rectangle permanently rendered.")
  682. Slab.NewLine()
  683. if Slab.BeginTree('DrawTree_Root_Opened', {Label = "Root", IsOpen = true}) then
  684. for I = 1, 5, 1 do
  685. Slab.BeginTree('DrawTree_Item_' .. I, {Label = "Item " .. I, IsLeaf = true, IsSelected = I == DrawTree_Opened_Selected})
  686. if Slab.IsControlClicked() then
  687. DrawTree_Opened_Selected = I
  688. end
  689. end
  690. Slab.EndTree()
  691. end
  692. end
  693. local DrawDialog_MessageBox = false
  694. local DrawDialog_MessageBox_Title = "Message Box"
  695. local DrawDialog_MessageBox_Message = "This is a message."
  696. local DrawDialog_FileDialog = ''
  697. local DrawDialog_FileDialog_Result = ""
  698. local function DrawDialog()
  699. Slab.Textf(
  700. "Dialog boxes are windows that rendered on top of everything else. These windows will consume input from all other windows " ..
  701. "and controls. These are useful for forcing users to interact with a window of importance, such as message boxes and " ..
  702. "file dialogs.")
  703. Slab.NewLine()
  704. Slab.Textf(
  705. "By clicking the button below, an example of a simple dialog box will be rendered.")
  706. if Slab.Button("Open Basic Dialog") then
  707. Slab.OpenDialog('DrawDialog_Basic')
  708. end
  709. if Slab.BeginDialog('DrawDialog_Basic', {Title = "Basic Dialog"}) then
  710. Slab.Text("This is a basic dialog box.")
  711. if Slab.Button("Close") then
  712. Slab.CloseDialog()
  713. end
  714. Slab.EndDialog()
  715. end
  716. Slab.NewLine()
  717. Slab.Separator()
  718. Slab.Textf(
  719. "Slab offers support for common dialog boxes such as message boxes. To display a message box, Slab.MessageBox must be called every " ..
  720. "frame. The buttons to be drawn must be passed in through the Buttons option. Once the user has made a selection, the button that was " ..
  721. "clicked is returned and the program can handle the response accordingly.")
  722. Slab.NewLine()
  723. Slab.Text("Title")
  724. Slab.SameLine()
  725. if Slab.Input('DrawDialog_MessageBox_Title', {Text = DrawDialog_MessageBox_Title}) then
  726. DrawDialog_MessageBox_Title = Slab.GetInputText()
  727. end
  728. Slab.NewLine()
  729. Slab.Text("Message")
  730. if Slab.Input('DrawDialog_MessageBox_Message', {Text = DrawDialog_MessageBox_Message, MultiLine = true, H = 75}) then
  731. DrawDialog_MessageBox_Message = Slab.GetInputText()
  732. end
  733. Slab.NewLine()
  734. if Slab.Button("Show Message Box") then
  735. DrawDialog_MessageBox = true
  736. end
  737. if DrawDialog_MessageBox then
  738. local Result = Slab.MessageBox(DrawDialog_MessageBox_Title, DrawDialog_MessageBox_Message, {Buttons = {"OK"}})
  739. if Result ~= "" then
  740. DrawDialog_MessageBox = false
  741. end
  742. end
  743. Slab.NewLine()
  744. Slab.Separator()
  745. Slab.Textf(
  746. "Slab offers a file dialog box so that user can select to open or save a file. This behaves similar to file dialogs found on " ..
  747. "various operating systems. Files can be filtered and a starting directory can be set. There are options for the user to select " ..
  748. "a single item or multiple items. As with the message box, the FileDialog option must be called every frame and the user response " ..
  749. "must be handled by the program.")
  750. Slab.NewLine()
  751. if Slab.Button("Open File") then
  752. DrawDialog_FileDialog = 'openfile'
  753. end
  754. Slab.SameLine()
  755. if Slab.Button("Open Directory") then
  756. DrawDialog_FileDialog = 'opendirectory'
  757. end
  758. Slab.SameLine()
  759. if Slab.Button("Save File") then
  760. DrawDialog_FileDialog = 'savefile'
  761. end
  762. if DrawDialog_FileDialog ~= '' then
  763. local Result = Slab.FileDialog({AllowMultiSelect = false, Type = DrawDialog_FileDialog})
  764. if Result.Button ~= "" then
  765. DrawDialog_FileDialog = ''
  766. if Result.Button == "OK" then
  767. DrawDialog_FileDialog_Result = Result.Files[1]
  768. end
  769. end
  770. end
  771. Slab.Textf(
  772. "Selected file: " .. DrawDialog_FileDialog_Result)
  773. end
  774. local DrawInteraction_MouseClicked_Left = 0
  775. local DrawInteraction_MouseClicked_Right = 0
  776. local DrawInteraction_MouseClicked_Middle = 0
  777. local DrawInteraction_MouseReleased_Left = 0
  778. local DrawInteraction_MouseReleased_Right = 0
  779. local DrawInteraction_MouseReleased_Middle = 0
  780. local DrawInteraction_MouseDoubleClicked_Left = 0
  781. local DrawInteraction_MouseDoubleClicked_Right = 0
  782. local DrawInteraction_MouseDoubleClicked_Middle = 0
  783. local DrawInteraction_MouseVoidClicked_Left = 0
  784. local DrawInteraction_KeyPressed_A = 0
  785. local DrawInteraction_KeyPressed_S = 0
  786. local DrawInteraction_KeyPressed_D = 0
  787. local DrawInteraction_KeyPressed_F = 0
  788. local DrawInteraction_KeyReleased_A = 0
  789. local DrawInteraction_KeyReleased_S = 0
  790. local DrawInteraction_KeyReleased_D = 0
  791. local DrawInteraction_KeyReleased_F = 0
  792. local function DrawInteraction()
  793. Slab.Textf(
  794. "Slab offers functions to query the user's input on a given frame. There are also functions to query for input on the most " ..
  795. "recently declared control. This can allow the implementation to use custom logic for controls to create custom behaviors.")
  796. Slab.NewLine()
  797. Slab.Textf(
  798. "Below are functions that query the state of the mouse. The IsMouseDown checks to see if a specific button is down on that " ..
  799. "frame. The IsMouseClicked will check to see if the state of a button went from up to down on that frame and the IsMouseReleased " ..
  800. "function checks to see if a button went from down to up on that frame.")
  801. local Left = Slab.IsMouseDown(1)
  802. local Right = Slab.IsMouseDown(2)
  803. local Middle = Slab.IsMouseDown(3)
  804. Slab.NewLine()
  805. Slab.Text("Left")
  806. Slab.SameLine()
  807. Slab.Text(Left and "Down" or "Up")
  808. Slab.Text("Right")
  809. Slab.SameLine()
  810. Slab.Text(Right and "Down" or "Up")
  811. Slab.Text("Middle")
  812. Slab.SameLine()
  813. Slab.Text(Middle and "Down" or "Up")
  814. Slab.NewLine()
  815. if Slab.IsMouseClicked(1) then DrawInteraction_MouseClicked_Left = DrawInteraction_MouseClicked_Left + 1 end
  816. if Slab.IsMouseClicked(2) then DrawInteraction_MouseClicked_Right = DrawInteraction_MouseClicked_Right + 1 end
  817. if Slab.IsMouseClicked(3) then DrawInteraction_MouseClicked_Middle = DrawInteraction_MouseClicked_Middle + 1 end
  818. if Slab.IsMouseReleased(1) then DrawInteraction_MouseReleased_Left = DrawInteraction_MouseReleased_Left + 1 end
  819. if Slab.IsMouseReleased(2) then DrawInteraction_MouseReleased_Right = DrawInteraction_MouseReleased_Right + 1 end
  820. if Slab.IsMouseReleased(3) then DrawInteraction_MouseReleased_Middle = DrawInteraction_MouseReleased_Middle + 1 end
  821. Slab.Text("Left Clicked: " .. DrawInteraction_MouseClicked_Left)
  822. Slab.SameLine()
  823. Slab.Text("Released: " .. DrawInteraction_MouseReleased_Left)
  824. Slab.Text("Right Clicked: " .. DrawInteraction_MouseClicked_Right)
  825. Slab.SameLine()
  826. Slab.Text("Released: " .. DrawInteraction_MouseReleased_Right)
  827. Slab.Text("Middle Clicked: " .. DrawInteraction_MouseClicked_Middle)
  828. Slab.SameLine()
  829. Slab.Text("Released: " .. DrawInteraction_MouseReleased_Middle)
  830. Slab.NewLine()
  831. Slab.Textf(
  832. "Slab offers functions to detect if the mouse was double-clicked or if a mouse button is being dragged.")
  833. Slab.NewLine()
  834. if Slab.IsMouseDoubleClicked(1) then DrawInteraction_MouseDoubleClicked_Left = DrawInteraction_MouseDoubleClicked_Left + 1 end
  835. if Slab.IsMouseDoubleClicked(2) then DrawInteraction_MouseDoubleClicked_Right = DrawInteraction_MouseDoubleClicked_Right + 1 end
  836. if Slab.IsMouseDoubleClicked(3) then DrawInteraction_MouseDoubleClicked_Middle = DrawInteraction_MouseDoubleClicked_Middle + 1 end
  837. Slab.Text("Left Double Clicked: " .. DrawInteraction_MouseDoubleClicked_Left)
  838. Slab.Text("Right Double Clicked: " .. DrawInteraction_MouseDoubleClicked_Right)
  839. Slab.Text("Middle Double Clicked: " .. DrawInteraction_MouseDoubleClicked_Middle)
  840. Slab.NewLine()
  841. local LeftDrag = Slab.IsMouseDragging(1)
  842. local RightDrag = Slab.IsMouseDragging(2)
  843. local MiddleDrag = Slab.IsMouseDragging(3)
  844. Slab.Text("Left Drag: " .. tostring(LeftDrag))
  845. Slab.Text("Right Drag: " .. tostring(RightDrag))
  846. Slab.Text("Middle Drag: " .. tostring(MiddleDrag))
  847. Slab.NewLine()
  848. Slab.Textf(
  849. "The mouse position relative to the viewport and relative to the current window can also be queried. Slab also offers retrieving " ..
  850. "the mouse delta.")
  851. Slab.NewLine()
  852. local X, Y = Slab.GetMousePosition()
  853. local WinX, WinY = Slab.GetMousePositionWindow()
  854. local DeltaX, DeltaY = Slab.GetMouseDelta()
  855. Slab.Text("X: " .. X .. " Y: " .. Y)
  856. Slab.Text("Window X: " .. WinX .. " Window Y: " .. WinY)
  857. Slab.Text("Delta X: " .. DeltaX .. " Delta Y: " .. DeltaY)
  858. Slab.Textf(
  859. "Slab also offers functions to test if the user is interacting with the non-UI layer. The IsVoidHovered and IsVoidClicked " ..
  860. "behave the same way as IsControlHovered and IsControlClicked except will only return true when it is in a non-UI area.")
  861. Slab.NewLine()
  862. if Slab.IsVoidClicked(1) then
  863. DrawInteraction_MouseVoidClicked_Left = DrawInteraction_MouseVoidClicked_Left + 1
  864. end
  865. local IsVoidHovered = Slab.IsVoidHovered()
  866. Slab.Text("Left Void Clicked: " .. DrawInteraction_MouseVoidClicked_Left)
  867. Slab.Text("Is Void Hovered: " .. tostring(IsVoidHovered))
  868. Slab.NewLine()
  869. Slab.Separator()
  870. Slab.Textf(
  871. "Slab offers functions to check for the state of a specific keyboard key. The key code to use are the ones defined by LÖVE " ..
  872. "which can be found on the wiki. Below we will check for the key states of the A, S, D, F keys.")
  873. Slab.NewLine()
  874. local IsDown_A = Slab.IsKeyDown('a')
  875. local IsDown_S = Slab.IsKeyDown('s')
  876. local IsDown_D = Slab.IsKeyDown('d')
  877. local IsDown_F = Slab.IsKeyDown('f')
  878. if Slab.IsKeyPressed('a') then DrawInteraction_KeyPressed_A = DrawInteraction_KeyPressed_A + 1 end
  879. if Slab.IsKeyPressed('s') then DrawInteraction_KeyPressed_S = DrawInteraction_KeyPressed_S + 1 end
  880. if Slab.IsKeyPressed('d') then DrawInteraction_KeyPressed_D = DrawInteraction_KeyPressed_D + 1 end
  881. if Slab.IsKeyPressed('f') then DrawInteraction_KeyPressed_F = DrawInteraction_KeyPressed_F + 1 end
  882. if Slab.IsKeyReleased('a') then DrawInteraction_KeyReleased_A = DrawInteraction_KeyReleased_A + 1 end
  883. if Slab.IsKeyReleased('s') then DrawInteraction_KeyReleased_S = DrawInteraction_KeyReleased_S + 1 end
  884. if Slab.IsKeyReleased('d') then DrawInteraction_KeyReleased_D = DrawInteraction_KeyReleased_D + 1 end
  885. if Slab.IsKeyReleased('f') then DrawInteraction_KeyReleased_F = DrawInteraction_KeyReleased_F + 1 end
  886. Slab.Text("A Down: " .. tostring(IsDown_A))
  887. Slab.Text("S Down: " .. tostring(IsDown_S))
  888. Slab.Text("D Down: " .. tostring(IsDown_D))
  889. Slab.Text("F Down: " .. tostring(IsDown_F))
  890. Slab.NewLine()
  891. Slab.Text("A Pressed: " .. DrawInteraction_KeyPressed_A)
  892. Slab.Text("S Pressed: " .. DrawInteraction_KeyPressed_S)
  893. Slab.Text("D Pressed: " .. DrawInteraction_KeyPressed_D)
  894. Slab.Text("F Pressed: " .. DrawInteraction_KeyPressed_F)
  895. Slab.NewLine()
  896. Slab.Text("A Released: " .. DrawInteraction_KeyReleased_A)
  897. Slab.Text("S Released: " .. DrawInteraction_KeyReleased_S)
  898. Slab.Text("D Released: " .. DrawInteraction_KeyReleased_D)
  899. Slab.Text("F Released: " .. DrawInteraction_KeyReleased_F)
  900. end
  901. local DrawShapes_Rectangle_Color = {1, 0, 0, 1}
  902. local DrawShapes_Rectangle_ChangeColor = false
  903. local DrawShapes_Rectangle_Rounding = {0, 0, 2.0, 2.0}
  904. local DrawShapes_Circle_Radius = 32.0
  905. local DrawShapes_Circle_Segments = 24
  906. local DrawShapes_Circle_Mode = 'fill'
  907. local DrawShapes_Triangle_Radius = 32.0
  908. local DrawShapes_Triangle_Rotation = 0
  909. local DrawShapes_Triangle_Mode = 'fill'
  910. local DrawShapes_Modes = {'fill', 'line'}
  911. local DrawShapes_Line_Width = 1.0
  912. local DrawShapes_Curve = {0, 0, 150, 150, 300, 0}
  913. local DrawShapes_ControlPoint_Size = 7.5
  914. local DrawShapes_ControlPoint_Index = 0
  915. local DrawShapes_Polygon = {10, 10, 150, 25, 175, 75, 50, 125}
  916. local DrawShapes_Polygon_Mode = 'fill'
  917. local function DrawShapes_Rectangle_Rounding_Input(Corner, Index)
  918. Slab.Text(Corner)
  919. Slab.SameLine()
  920. if Slab.Input('DrawShapes_Rectangle_Rounding_' .. Corner, {Text = tostring(DrawShapes_Rectangle_Rounding[Index]), NumbersOnly = true, MinNumber = 0, ReturnOnText = false}) then
  921. DrawShapes_Rectangle_Rounding[Index] = Slab.GetInputNumber()
  922. end
  923. end
  924. local function DrawShapes()
  925. Slab.Textf(
  926. "Slab offers functions to draw basic shapes to the window. These shapes can complement the controls provided by Slab.")
  927. Slab.NewLine()
  928. Slab.Textf(
  929. "Below is an invisible button combined with a rectangle. Click on the rectangle to change the color.")
  930. local X, Y = Slab.GetCursorPos()
  931. Slab.Rectangle({W = 150, H = 25, Color = DrawShapes_Rectangle_Color})
  932. Slab.SetCursorPos(X, Y)
  933. if Slab.Button("", {W = 150, H = 25, Invisible = true}) then
  934. DrawShapes_Rectangle_ChangeColor = true
  935. end
  936. if DrawShapes_Rectangle_ChangeColor then
  937. local Result = Slab.ColorPicker({Color = DrawShapes_Rectangle_Color})
  938. if Result.Button ~= "" then
  939. DrawShapes_Rectangle_ChangeColor = false
  940. if Result.Button == "OK" then
  941. DrawShapes_Rectangle_Color = Result.Color
  942. end
  943. end
  944. end
  945. Slab.NewLine()
  946. Slab.Textf(
  947. "Rectangle corner rounding can be defined in multiple ways. The rounding option can take a single number, which will apply rounding to all corners. The option " ..
  948. "can also accept a table, with each index affecting a single corner. The order this happens in is top left, top right, bottom right, and bottom left.")
  949. Slab.NewLine()
  950. DrawShapes_Rectangle_Rounding_Input('TL', 1)
  951. Slab.SameLine()
  952. DrawShapes_Rectangle_Rounding_Input('TR', 2)
  953. Slab.SameLine()
  954. DrawShapes_Rectangle_Rounding_Input('BR', 3)
  955. Slab.SameLine()
  956. DrawShapes_Rectangle_Rounding_Input('BL', 4)
  957. Slab.NewLine()
  958. Slab.Rectangle({W = 150.0, H = 75.0, Rounding = DrawShapes_Rectangle_Rounding, Outline = true, Color = {0, 1, 0, 1}})
  959. Slab.NewLine()
  960. Slab.Separator()
  961. Slab.Textf(
  962. "Circles are drawn by defining a radius. Along with the color the number of segments can be set as well.")
  963. Slab.NewLine()
  964. Slab.Text("Radius")
  965. Slab.SameLine()
  966. if Slab.Input('DrawShapes_Circle_Radius', {Text = tostring(DrawShapes_Circle_Radius), NumbersOnly = true, MinNumber = 0, ReturnOnText = false}) then
  967. DrawShapes_Circle_Radius = Slab.GetInputNumber()
  968. end
  969. Slab.SameLine()
  970. Slab.Text("Segments")
  971. Slab.SameLine()
  972. if Slab.Input('DrawShapes_Circle_Segments', {Text = tostring(DrawShapes_Circle_Segments), NumbersOnly = true, MinNumber = 0, ReturnOnText = false}) then
  973. DrawShapes_Circle_Segments = Slab.GetInputNumber()
  974. end
  975. Slab.SameLine()
  976. Slab.Text("Mode")
  977. Slab.SameLine()
  978. if Slab.BeginComboBox('DrawShapes_Circle_Mode', {Selected = DrawShapes_Circle_Mode}) then
  979. for I, V in ipairs(DrawShapes_Modes) do
  980. if Slab.TextSelectable(V) then
  981. DrawShapes_Circle_Mode = V
  982. end
  983. end
  984. Slab.EndComboBox()
  985. end
  986. Slab.Circle({Radius = DrawShapes_Circle_Radius, Segments = DrawShapes_Circle_Segments, Color = {1, 1, 1, 1}, Mode = DrawShapes_Circle_Mode})
  987. Slab.NewLine()
  988. Slab.Separator()
  989. Slab.Textf(
  990. "Triangles are drawn by defining a radius, which is the length from the center of the triangle to the 3 points. A rotation in degrees " ..
  991. "can be specified to rotate the triangle.")
  992. Slab.NewLine()
  993. Slab.Text("Radius")
  994. Slab.SameLine()
  995. if Slab.Input('DrawShapes_Triangle_Radius', {Text = tostring(DrawShapes_Triangle_Radius), NumbersOnly = true, MinNumber = 0, ReturnOnText = false}) then
  996. DrawShapes_Triangle_Radius = Slab.GetInputNumber()
  997. end
  998. Slab.SameLine()
  999. Slab.Text("Rotation")
  1000. Slab.SameLine()
  1001. if Slab.Input('DrawShapes_Triangle_Rotation', {Text = tostring(DrawShapes_Triangle_Rotation), NumbersOnly = true, MinNumber = 0, ReturnOnText = false}) then
  1002. DrawShapes_Triangle_Rotation = Slab.GetInputNumber()
  1003. end
  1004. Slab.SameLine()
  1005. Slab.Text("Mode")
  1006. Slab.SameLine()
  1007. if Slab.BeginComboBox('DrawShapes_Triangle_Mode', {Selected = DrawShapes_Triangle_Mode}) then
  1008. for I, V in ipairs(DrawShapes_Modes) do
  1009. if Slab.TextSelectable(V) then
  1010. DrawShapes_Triangle_Mode = V
  1011. end
  1012. end
  1013. Slab.EndComboBox()
  1014. end
  1015. Slab.Triangle({Radius = DrawShapes_Triangle_Radius, Rotation = DrawShapes_Triangle_Rotation, Color = {0, 1, 0, 1}, Mode = DrawShapes_Triangle_Mode})
  1016. Slab.NewLine()
  1017. Slab.Separator()
  1018. Slab.Textf(
  1019. "Lines are defined by two points. The function only takes in a single point which defines the end point while the start point is defined by the current " ..
  1020. "cursor position. Both the line width and color can be defined.")
  1021. Slab.NewLine()
  1022. Slab.Text("Width")
  1023. Slab.SameLine()
  1024. if Slab.Input('DrawShapes_Line_Width', {Text = tostring(DrawShapes_Line_Width), NumbersOnly = true, ReturnOnText = false, MinNumber = 1.0}) then
  1025. DrawShapes_Line_Width = Slab.GetInputNumber()
  1026. end
  1027. Slab.NewLine()
  1028. X, Y = Slab.GetCursorPos({Absolute = true})
  1029. local WinW, WinH = Slab.GetWindowActiveSize()
  1030. Slab.Line(X + WinW * 0.5, Y, {Width = DrawShapes_Line_Width, Color = {1, 1, 0, 1}})
  1031. Slab.NewLine()
  1032. Slab.Separator()
  1033. Slab.Textf(
  1034. "Bezier curves can be defined through a set of points and added to a Slab window. The points given must be in local space. Slab will translate the " ..
  1035. "curve to the current cursor position. Along with the ability to draw the curve, Slab offers functions to query information about the curve, such as " ..
  1036. "the number of control points defined, the position of a control point, and the ability to evaluate the position of a curve given a Time value. " ..
  1037. "There is also a function to evaluate the curve with the current X mouse position.")
  1038. Slab.NewLine()
  1039. Slab.Curve(DrawShapes_Curve)
  1040. X, Y = Slab.GetCursorPos({Absolute = true})
  1041. Slab.SameLine({CenterY = true, Pad = 16})
  1042. local EvalX, EvalY = Slab.EvaluateCurveMouse()
  1043. Slab.Text(string.format("X: %.2f Y: %.2f", EvalX, EvalY))
  1044. EvalX, EvalY = Slab.EvaluateCurveMouse({LocalSpace = false})
  1045. Slab.SetCursorPos(EvalX, EvalY, {Absolute = true})
  1046. Slab.Circle({Color = {1, 1, 1, 1}, Radius = DrawShapes_ControlPoint_Size * 0.5})
  1047. local HalfSize = DrawShapes_ControlPoint_Size * 0.5
  1048. for I = 1, Slab.GetCurveControlPointCount(), 1 do
  1049. local PX, PY = Slab.GetCurveControlPoint(I, {LocalSpace = false})
  1050. Slab.SetCursorPos(PX - HalfSize, PY - HalfSize, {Absolute = true})
  1051. Slab.Rectangle({W = DrawShapes_ControlPoint_Size, H = DrawShapes_ControlPoint_Size, Color = {1, 1, 1, 1}})
  1052. if Slab.IsControlClicked() then
  1053. DrawShapes_ControlPoint_Index = I
  1054. end
  1055. end
  1056. if DrawShapes_ControlPoint_Index > 0 and Slab.IsMouseDragging() then
  1057. local DeltaX, DeltaY = Slab.GetMouseDelta()
  1058. local P2 = DrawShapes_ControlPoint_Index * 2
  1059. local P1 = P2 - 1
  1060. DrawShapes_Curve[P1] = DrawShapes_Curve[P1] + DeltaX
  1061. DrawShapes_Curve[P2] = DrawShapes_Curve[P2] + DeltaY
  1062. end
  1063. if Slab.IsMouseReleased() then
  1064. DrawShapes_ControlPoint_Index = 0
  1065. end
  1066. Slab.SetCursorPos(X, Y, {Absolute = true})
  1067. Slab.NewLine()
  1068. Slab.Separator()
  1069. Slab.Textf(
  1070. "Polygons can be drawn by passing in a list of points into the Polygon function. The points, like the curve, should be defined in local space. Slab will " ..
  1071. "then translate the points to the current cursor position.")
  1072. Slab.NewLine()
  1073. Slab.Text("Mode")
  1074. Slab.SameLine()
  1075. if Slab.BeginComboBox('DrawShapes_Polygon_Mode', {Selected = DrawShapes_Polygon_Mode}) then
  1076. for I, V in ipairs(DrawShapes_Modes) do
  1077. if Slab.TextSelectable(V) then
  1078. DrawShapes_Polygon_Mode = V
  1079. end
  1080. end
  1081. Slab.EndComboBox()
  1082. end
  1083. Slab.Polygon(DrawShapes_Polygon, {Color = {0, 0, 1, 1}, Mode = DrawShapes_Polygon_Mode})
  1084. end
  1085. local DrawWindow_X = 900
  1086. local DrawWindow_Y = 100
  1087. local DrawWindow_W = 200
  1088. local DrawWindow_H = 200
  1089. local DrawWindow_Title = "Example"
  1090. local DrawWindow_ResetLayout = false
  1091. local DrawWindow_ResetSize = false
  1092. local DrawWindow_AutoSizeWindow = true
  1093. local DrawWindow_AllowResize = true
  1094. local DrawWindow_AllowMove = true
  1095. local DrawWindow_AllowFocus = true
  1096. local DrawWindow_Border = 4.0
  1097. local DrawWindow_BgColor = nil
  1098. local DrawWindow_BgColor_ChangeColor = false
  1099. local DrawWindow_NoOutline = false
  1100. local DrawWindow_SizerFilter = {}
  1101. local DrawWindow_SizerFiltersOptions = {
  1102. N = true,
  1103. S = true,
  1104. E = true,
  1105. W = true,
  1106. NW = true,
  1107. NE = true,
  1108. SW = true,
  1109. SE = true,
  1110. }
  1111. local function DrawWindow_SizerCheckBox(Key)
  1112. if Slab.CheckBox(DrawWindow_SizerFiltersOptions[Key], Key) then
  1113. DrawWindow_SizerFiltersOptions[Key] = not DrawWindow_SizerFiltersOptions[Key]
  1114. end
  1115. end
  1116. local function DrawWindow()
  1117. Slab.Textf(
  1118. "Windows are the basis for which all controls are rendered on and for all user interactions to occur. This area will contain information on the " ..
  1119. "various options that a window can take and what their expected behaviors will be. The window rendered to the right of this window will be affected " ..
  1120. "by the changes to the various parameters.")
  1121. Slab.NewLine()
  1122. Slab.Separator()
  1123. Slab.Textf(
  1124. "The title of the window can be customized. If no title exists, then the title bar is not rendered and the window can not be moved. There is also an " ..
  1125. "option, AllowMove, to disable movement even with the title bar.")
  1126. Slab.NewLine()
  1127. Slab.Text("Title")
  1128. Slab.SameLine()
  1129. if Slab.Input('DrawWindow_Title', {Text = DrawWindow_Title, ReturnOnText = false}) then
  1130. DrawWindow_Title = Slab.GetInputText()
  1131. end
  1132. Slab.SameLine()
  1133. if Slab.CheckBox(DrawWindow_AllowMove, "Allow Move") then
  1134. DrawWindow_AllowMove = not DrawWindow_AllowMove
  1135. end
  1136. Slab.NewLine()
  1137. Slab.Separator()
  1138. Slab.Textf(
  1139. "The default position of the window can be set with the X and Y options. The window can be moved from this position but the parameter values stay the same " ..
  1140. "as the window keeps track of any delta changes from the starting position. The window can be reset to the default position as described later on below.")
  1141. Slab.NewLine()
  1142. Slab.Text("X")
  1143. Slab.SameLine()
  1144. if Slab.Input('DrawWindow_X', {Text = tostring(DrawWindow_X), NumbersOnly = true, ReturnOnText = false}) then
  1145. DrawWindow_X = Slab.GetInputNumber()
  1146. DrawWindow_ResetLayout = true
  1147. end
  1148. Slab.SameLine()
  1149. Slab.Text("Y")
  1150. Slab.SameLine()
  1151. if Slab.Input('DrawWindow_Y', {Text = tostring(DrawWindow_Y), NumbersOnly = true, ReturnOnText = false}) then
  1152. DrawWindow_Y = Slab.GetInputNumber()
  1153. DrawWindow_ResetLayout = true
  1154. end
  1155. Slab.NewLine()
  1156. Slab.Separator()
  1157. Slab.Textf(
  1158. "The size of the window can be specified. However, windows by default are set to auto size with the AutoSizeWindow option, which resizes the window only when " ..
  1159. "controls are added to the window. If this option is disabled, then the W and H parameters will be applied to the window.\n" ..
  1160. "Similar to the window position, the window's size delta changes are stored by the window. The window's size can be reset to the default with the ResetSize " ..
  1161. "option.")
  1162. Slab.NewLine()
  1163. Slab.Text("W")
  1164. Slab.SameLine()
  1165. if Slab.Input('DrawWindow_W', {Text = tostring(DrawWindow_W), NumbersOnly = true, ReturnOnText = false, MinNumber = 0}) then
  1166. DrawWindow_W = Slab.GetInputNumber()
  1167. DrawWindow_ResetSize = true
  1168. end
  1169. Slab.SameLine()
  1170. Slab.Text("H")
  1171. Slab.SameLine()
  1172. if Slab.Input('DrawWindow_H', {Text = tostring(DrawWindow_H), NumbersOnly = true, ReturnOnText = false, MinNumber = 0}) then
  1173. DrawWindow_H = Slab.GetInputNumber()
  1174. DrawWindow_ResetSize = true
  1175. end
  1176. if Slab.CheckBox(DrawWindow_AutoSizeWindow, "Auto Size Window") then
  1177. DrawWindow_AutoSizeWindow = not DrawWindow_AutoSizeWindow
  1178. end
  1179. Slab.NewLine()
  1180. Slab.Separator()
  1181. Slab.Textf(
  1182. "Windows can be resized onluy if the AutoSizeWindow option is set false. By default, all sides and corners of a window can be resized, but this can be " ..
  1183. "modified by specifying which directions are allowed to be resized. There is also an option to completely disable resizing with the AllowResize option. " ..
  1184. "Below is a list of options that are available.")
  1185. Slab.NewLine()
  1186. if Slab.CheckBox(DrawWindow_AllowResize, "Allow Resize") then
  1187. DrawWindow_AllowResize = not DrawWindow_AllowResize
  1188. end
  1189. DrawWindow_SizerCheckBox('N')
  1190. DrawWindow_SizerCheckBox('S')
  1191. DrawWindow_SizerCheckBox('E')
  1192. DrawWindow_SizerCheckBox('W')
  1193. DrawWindow_SizerCheckBox('NW')
  1194. DrawWindow_SizerCheckBox('NE')
  1195. DrawWindow_SizerCheckBox('SW')
  1196. DrawWindow_SizerCheckBox('SE')
  1197. local FalseCount = 0
  1198. DrawWindow_SizerFilter = {}
  1199. for K, V in pairs(DrawWindow_SizerFiltersOptions) do
  1200. if V then
  1201. table.insert(DrawWindow_SizerFilter, K)
  1202. else
  1203. FalseCount = FalseCount + 1
  1204. end
  1205. end
  1206. if FalseCount == 0 then
  1207. DrawWindow_SizerFilter = {}
  1208. end
  1209. Slab.NewLine()
  1210. Slab.Separator()
  1211. Slab.Textf(
  1212. "Windows gain focus when the user clicks within the region of the window. When the window gains focus, it is brought to the top of the window stack. " ..
  1213. "Through the AllowFocus option, a window may have this behavior turned off.")
  1214. Slab.NewLine()
  1215. if Slab.CheckBox(DrawWindow_AllowFocus, "Allow Focus") then
  1216. DrawWindow_AllowFocus = not DrawWindow_AllowFocus
  1217. end
  1218. Slab.NewLine()
  1219. Slab.Separator()
  1220. Slab.Textf(
  1221. "Windows have a border defined which is how much space there is between the edges of the window and the contents of the window.")
  1222. Slab.NewLine()
  1223. Slab.Text("Border")
  1224. Slab.SameLine()
  1225. if Slab.Input('DrawWindow_Border', {Text = tostring(DrawWindow_Border), NumbersOnly = true, ReturnOnText = false, MinNumber = 0}) then
  1226. DrawWindow_Border = Slab.GetInputNumber()
  1227. end
  1228. Slab.NewLine()
  1229. Slab.Separator()
  1230. Slab.Textf(
  1231. "The ResetSize and ResetLayout options for windows will reset any delta changes to a window's position or size. It is recommended to only pass " ..
  1232. "in true for these options on a single frame if resetting the position or size is desired.")
  1233. Slab.NewLine()
  1234. if Slab.Button("Reset Layout") then
  1235. DrawWindow_ResetLayout = true
  1236. end
  1237. Slab.SameLine()
  1238. if Slab.Button("Reset Size") then
  1239. DrawWindow_ResetSize = true
  1240. end
  1241. Slab.NewLine()
  1242. Slab.Separator()
  1243. Slab.Textf(
  1244. "The background color of the window can be modified. Along with modifying the color, the outline of the window can be set to drawn or hidden." ..
  1245. "Hiding the outline and setting the background to be transparent will make only the controls be rendered within the window.")
  1246. if DrawWindow_BgColor == nil then
  1247. DrawWindow_BgColor = Slab.GetStyle().WindowBackgroundColor
  1248. end
  1249. if Slab.Button("Change Backgound Color") then
  1250. DrawWindow_BgColor_ChangeColor = true
  1251. end
  1252. if Slab.CheckBox(DrawWindow_NoOutline, "No Outline") then
  1253. DrawWindow_NoOutline = not DrawWindow_NoOutline
  1254. end
  1255. if DrawWindow_BgColor_ChangeColor then
  1256. local Result = Slab.ColorPicker({Color = DrawWindow_BgColor})
  1257. if Result.Button ~= "" then
  1258. DrawWindow_BgColor_ChangeColor = false
  1259. if Result.Button == "OK" then
  1260. DrawWindow_BgColor = Result.Color
  1261. end
  1262. end
  1263. end
  1264. Slab.BeginWindow('DrawWindow_Example', {
  1265. Title = DrawWindow_Title,
  1266. X = DrawWindow_X,
  1267. Y = DrawWindow_Y,
  1268. W = DrawWindow_W,
  1269. H = DrawWindow_H,
  1270. ResetLayout = DrawWindow_ResetLayout,
  1271. ResetSize = DrawWindow_ResetSize,
  1272. AutoSizeWindow = DrawWindow_AutoSizeWindow,
  1273. SizerFilter = DrawWindow_SizerFilter,
  1274. AllowResize = DrawWindow_AllowResize,
  1275. AllowMove = DrawWindow_AllowMove,
  1276. AllowFocus = DrawWindow_AllowFocus,
  1277. Border = DrawWindow_Border,
  1278. BgColor = DrawWindow_BgColor,
  1279. NoOutline = DrawWindow_NoOutline
  1280. })
  1281. Slab.Text("Hello World")
  1282. Slab.EndWindow()
  1283. DrawWindow_ResetLayout = false
  1284. DrawWindow_ResetSize = false
  1285. end
  1286. local DrawTooltip_CheckBox = false
  1287. local DrawTooltip_Radio = 1
  1288. local DrawTooltip_ComboBox_Items = {"Button", "Check Box", "Combo Box", "Image", "Input", "Text", "Tree"}
  1289. local DrawTooltip_ComboBox_Selected = "Button"
  1290. local DrawTooltip_Image = SLAB_PATH .. "/Internal/Resources/Textures/power.png"
  1291. local DrawTooltip_Input = "This is an input box."
  1292. local function DrawTooltip()
  1293. Slab.Textf(
  1294. "Slab offers tooltips to be rendered when the user has hovered over the control for a period of time. Not all controls are currently supported, " ..
  1295. "and this window will show examples for tooltips on the supported controls.")
  1296. Slab.NewLine()
  1297. Slab.Button("Button", {Tooltip = "This is a button."})
  1298. Slab.NewLine()
  1299. if Slab.CheckBox(DrawTooltip_CheckBox, "Check Box", {Tooltip = "This is a check box."}) then
  1300. DrawTooltip_CheckBox = not DrawTooltip_CheckBox
  1301. end
  1302. Slab.NewLine()
  1303. for I = 1, 3, 1 do
  1304. if Slab.RadioButton("Radio " .. I, {SelectedIndex = DrawTooltip_Radio, Index = I, Tooltip = "This is radio button " .. I}) then
  1305. DrawTooltip_Radio = I
  1306. end
  1307. end
  1308. Slab.NewLine()
  1309. if Slab.BeginComboBox('DrawTooltip_ComboBox', {Selected = DrawTooltip_ComboBox_Selected, Tooltip = "This is a combo box."}) then
  1310. for I, V in ipairs(DrawTooltip_ComboBox_Items) do
  1311. if Slab.TextSelectable(V) then
  1312. DrawTooltip_ComboBox_Selected = V
  1313. end
  1314. end
  1315. Slab.EndComboBox()
  1316. end
  1317. Slab.NewLine()
  1318. Slab.Image('DrawTooltip_Image', {Path = DrawTooltip_Image, Tooltip = "This is an image."})
  1319. Slab.NewLine()
  1320. if Slab.Input('DrawTooltip_Input', {Text = DrawTooltip_Input, Tooltip = DrawTooltip_Input}) then
  1321. DrawTooltip_Input = Slab.GetInputText()
  1322. end
  1323. Slab.NewLine()
  1324. if Slab.BeginTree('DrawTooltip_Tree_Root', {Label = "Root", Tooltip = "This is the root tree item."}) then
  1325. Slab.BeginTree('DrawTooltip_Tree_Child', {Label = "Child", Tooltip = "This is the child tree item.", IsLeaf = true})
  1326. Slab.EndTree()
  1327. end
  1328. end
  1329. local DrawStats_SetPosition = false
  1330. local DrawStats_EncodeIterations = 20
  1331. local DrawStats_EncodeLength = 500
  1332. local function DrawStats()
  1333. Slab.Textf(
  1334. "The Slab API offers functions that track the performance of desired sections of code. With these functions coupled together with the debug " ..
  1335. "performance window, end-users will be able to see bottlenecks located within their code base quickly. To display the performance window, " ..
  1336. "call the SlabDebug.Performance function.")
  1337. Slab.NewLine()
  1338. Slab.Separator()
  1339. if not DrawStats_SetPosition then
  1340. SlabDebug.Performance_SetPosition(800.0, 175.0)
  1341. DrawStats_SetPosition = true
  1342. end
  1343. Slab.Textf(
  1344. "This page has an example of capturing the performance of encoding data. The iterations and length can be changed to show how the performance is " ..
  1345. "impacted when these values change.")
  1346. Slab.NewLine()
  1347. Slab.Text("Iterations")
  1348. Slab.SameLine()
  1349. if Slab.Input('DrawStats_EncodeIterations', {Text = tostring(DrawStats_EncodeIterations), ReturnOnText = false, NumbersOnly = true, MinNumber = 0}) then
  1350. DrawStats_EncodeIterations = Slab.GetInputNumber()
  1351. end
  1352. Slab.SameLine()
  1353. Slab.Text("Length")
  1354. Slab.SameLine()
  1355. if Slab.Input('DrawStats_EncodeLength', {Text = tostring(DrawStats_EncodeLength), ReturnOnText = false, NumbersOnly = true, MinNumber = 0}) then
  1356. DrawStats_EncodeLength = Slab.GetInputNumber()
  1357. end
  1358. local StatHandle = Slab.BeginStat('Encode', 'Slab Test')
  1359. for I = 1, DrawStats_EncodeIterations, 1 do
  1360. local LengthStatHandle = Slab.BeginStat('Encode Length', 'Slab Test')
  1361. local Data = ""
  1362. for J = 1, DrawStats_EncodeLength, 1 do
  1363. local Byte = love.math.random(255)
  1364. Data = Data .. string.char(Byte)
  1365. end
  1366. love.data.encode('string', 'hex', Data)
  1367. Slab.EndStat(LengthStatHandle)
  1368. end
  1369. Slab.EndStat(StatHandle)
  1370. SlabDebug.Performance()
  1371. end
  1372. local DrawLayout_AlignX = 'left'
  1373. local DrawLayout_AlignY = 'top'
  1374. local DrawLayout_AlignRowY = 'top'
  1375. local DrawLayout_AlignX_Options = {'left', 'center', 'right'}
  1376. local DrawLayout_AlignY_Options = {'top', 'center', 'bottom'}
  1377. local DrawLayout_Radio = 1
  1378. local DrawLayout_Input = "Input Control"
  1379. local DrawLayout_ListBox_Selected = 1
  1380. local DrawLayout_Columns = 3
  1381. local function DrawLayout()
  1382. Slab.Textf(
  1383. "The layout API allows for controls to be grouped together and aligned to a specific position based on the window. " ..
  1384. "These controls can be aligned to the left, the center, or the right part of a window horizontally. They can also " ..
  1385. "be aligned to the top, the center, or the bottom vertically in a window. Multiple controls can be declared on the " ..
  1386. "same line and the API will properly align on the controls on the same line. Below are examples of how this API can " ..
  1387. "be utilized.")
  1388. Slab.NewLine()
  1389. Slab.Separator()
  1390. Slab.Textf(
  1391. "The below example shows how controls can be aligned within a window. Use the below options to dictate where the next " ..
  1392. "set of controls are aligned.")
  1393. Slab.NewLine()
  1394. Slab.BeginLayout('DrawLayout_Options', {AlignX = 'center'})
  1395. Slab.Text("AlignX")
  1396. Slab.SameLine()
  1397. if Slab.BeginComboBox('DrawLayout_AlignX', {Selected = DrawLayout_AlignX}) then
  1398. for I, V in ipairs(DrawLayout_AlignX_Options) do
  1399. if Slab.TextSelectable(V) then
  1400. DrawLayout_AlignX = V
  1401. end
  1402. end
  1403. Slab.EndComboBox()
  1404. end
  1405. Slab.SameLine()
  1406. Slab.Text("AlignY")
  1407. Slab.SameLine()
  1408. if Slab.BeginComboBox('DrawLayout_AlignY', {Selected = DrawLayout_AlignY}) then
  1409. for I, V in ipairs(DrawLayout_AlignY_Options) do
  1410. if Slab.TextSelectable(V) then
  1411. DrawLayout_AlignY = V
  1412. end
  1413. end
  1414. Slab.EndComboBox()
  1415. end
  1416. Slab.SameLine()
  1417. Slab.Text("AlignRowY")
  1418. Slab.SameLine()
  1419. if Slab.BeginComboBox('DrawLayout_AlignRowY', {Selected = DrawLayout_AlignRowY}) then
  1420. for I, V in ipairs(DrawLayout_AlignY_Options) do
  1421. if Slab.TextSelectable(V) then
  1422. DrawLayout_AlignRowY = V
  1423. end
  1424. end
  1425. Slab.EndComboBox()
  1426. end
  1427. Slab.EndLayout()
  1428. Slab.NewLine()
  1429. Slab.BeginLayout('DrawLayout_General', {AlignX = DrawLayout_AlignX, AlignY = DrawLayout_AlignY, AlignRowY = DrawLayout_AlignRowY})
  1430. Slab.Button("Button 1")
  1431. Slab.SameLine()
  1432. Slab.Button("Button 2", {W = 150})
  1433. Slab.Button("Button")
  1434. Slab.SameLine()
  1435. Slab.Button("Button", {W = 50, H = 50, Tooltip = "This is a large button."})
  1436. Slab.SameLine()
  1437. Slab.Button("Button")
  1438. Slab.NewLine()
  1439. Slab.Text("New Lines are supported too.")
  1440. Slab.EndLayout()
  1441. Slab.NewLine()
  1442. Slab.Separator()
  1443. Slab.Textf(
  1444. "Controls can also be expanded in the width and height. Only controls that can have their size modified through the API " ..
  1445. "will be affected by these options. The controls that will be affected are buttons, combo boxes (only the width), " ..
  1446. "input controls, and list boxes. Non-expandable controls such as text can be mixed in with the controls and the size " ..
  1447. "of the controls will be adjusted accordingly.")
  1448. Slab.NewLine()
  1449. Slab.BeginLayout('DrawLayout_Expand', {ExpandW = true, ExpandH = true})
  1450. Slab.Button("OK")
  1451. Slab.SameLine()
  1452. Slab.Text("Hello")
  1453. Slab.SameLine()
  1454. Slab.Input('DrawLayout_ExpandInput')
  1455. Slab.SameLine()
  1456. if Slab.BeginComboBox('DrawLayout_ExpandComboBox') then
  1457. Slab.EndComboBox()
  1458. end
  1459. Slab.SameLine()
  1460. Slab.BeginListBox('DrawLayout_ExpandListBox', {H = 0})
  1461. Slab.EndListBox()
  1462. Slab.Button("Cancel")
  1463. Slab.EndLayout()
  1464. Slab.NewLine()
  1465. Slab.Separator()
  1466. Slab.Textf(
  1467. "Controls can be layed out in columns. The 'Columns' option is a number that tells the layout how many columns to allocate for " ..
  1468. "positioning the controls. The 'SetLayoutColumn' function sets the current active column and all controls will be placed within " ..
  1469. "the bounds of that column.")
  1470. Slab.NewLine()
  1471. Slab.BeginLayout('DrawLayout_Columns_Options', {AlignX = 'center'})
  1472. Slab.Text("Columns")
  1473. Slab.SameLine()
  1474. if Slab.Input('DrawLayout_Columns_Input', {Text = tostring(DrawLayout_Columns), ReturnOnText = false, MinNumber = 1, NumbersOnly = true}) then
  1475. DrawLayout_Columns = Slab.GetInputNumber()
  1476. end
  1477. Slab.EndLayout()
  1478. Slab.NewLine()
  1479. Slab.BeginLayout('DrawLayout_Columns', {Columns = DrawLayout_Columns, AlignX = 'center'})
  1480. for I = 1, DrawLayout_Columns, 1 do
  1481. Slab.SetLayoutColumn(I)
  1482. Slab.Text("Column " .. I)
  1483. Slab.Text("This is a very long string")
  1484. end
  1485. Slab.EndLayout()
  1486. end
  1487. local DrawFonts_Roboto = nil
  1488. local DrawFonts_Roboto_Path = string.gsub(SLAB_PATH, "%.", "/") .. "/Internal/Resources/Fonts/Roboto-Regular.ttf"
  1489. local function DrawFonts()
  1490. if DrawFonts_Roboto == nil then
  1491. DrawFonts_Roboto = love.graphics.newFont(DrawFonts_Roboto_Path, 18)
  1492. end
  1493. Slab.Textf(
  1494. "Fonts can be pushed to a stack to alter the rendering of any text. All controls will use this pushed font until " ..
  1495. "the font is popped from the stack, using the last pushed font or the default font. Below is an example of font " ..
  1496. "being pushed to the stack to render a single text control and then being popped before the next text control.")
  1497. Slab.NewLine()
  1498. Slab.PushFont(DrawFonts_Roboto)
  1499. Slab.Text("This text control is using the Roboto font with point size of 18.")
  1500. Slab.PopFont()
  1501. Slab.NewLine()
  1502. Slab.Text("This text control is using the default font.")
  1503. end
  1504. local DrawTab_NumWindows = 5
  1505. local function DrawTab()
  1506. Slab.Textf(
  1507. "The Tab API allows multiple windows to be grouped into a single window with the title of each window displayed " ..
  1508. "in the title bar. The user can then select which window to display by selecting the window's title in the list. " ..
  1509. "If the number of titles exceed the width of the window, then an arrow will be rendered to allow the user to select " ..
  1510. "a non-visible window title from a dropdown list.")
  1511. Slab.NewLine()
  1512. Slab.Separator()
  1513. Slab.BeginLayout('DrawTab.Layout', {AlignX = 'center'})
  1514. Slab.Text("Tabs")
  1515. Slab.SameLine()
  1516. if Slab.Input('DrawTab.NumWindows', {Text = tostring(DrawTab_NumWindows), NumbersOnly = true, MinNumber = 1, ReturnOnText = false}) then
  1517. DrawTab_NumWindows = Slab.GetInputNumber()
  1518. end
  1519. Slab.EndLayout()
  1520. Slab.BeginTab('DrawTab.Tabs')
  1521. for I = 1, DrawTab_NumWindows, 1 do
  1522. Slab.BeginWindow('DrawTab.Tabs.Window.' .. I, {Title = "Tab " .. I, X = 900})
  1523. Slab.Text("Tabbed window " .. I)
  1524. Slab.EndWindow()
  1525. end
  1526. Slab.EndTab()
  1527. end
  1528. local DrawDock_Enabled = {
  1529. ['Left'] = false,
  1530. ['Right'] = false,
  1531. ['Bottom'] = false
  1532. }
  1533. local function DrawDock()
  1534. Slab.Textf(
  1535. "Slab offers the ability to dock a moving window to a side of a window. This allows for organizing windows and locking " ..
  1536. "their position and also allows for resizing the window. Multiple windows can be docked as well. The dockable sides are " ..
  1537. "to the left, right, and bottom. Each side is disabled by default, but can be enabled through the SetDockEnabled function.")
  1538. Slab.NewLine()
  1539. Slab.Separator()
  1540. for K, V in pairs(DrawDock_Enabled) do
  1541. if Slab.CheckBox(V, K) then
  1542. DrawDock_Enabled[K] = not V
  1543. Slab.SetDockEnabled({[K] = not V})
  1544. end
  1545. end
  1546. end
  1547. local DrawSlabTest = true
  1548. function SlabTest.MainMenuBar()
  1549. if Slab.BeginMainMenuBar() then
  1550. if Slab.BeginMenu("File") then
  1551. if Slab.MenuItemChecked("Slab Test", DrawSlabTest) then
  1552. DrawSlabTest = not DrawSlabTest
  1553. end
  1554. if Slab.MenuItem("Quit") then
  1555. love.event.quit()
  1556. end
  1557. Slab.EndMenu()
  1558. end
  1559. SlabDebug.Menu()
  1560. Slab.EndMainMenuBar()
  1561. end
  1562. end
  1563. local Categories = {
  1564. {"Overview", DrawOverview},
  1565. {"Window", DrawWindow},
  1566. {"Buttons", DrawButtons},
  1567. {"Text", DrawText},
  1568. {"Check Box", DrawCheckBox},
  1569. {"Radio Button", DrawRadioButton},
  1570. {"Menus", DrawMenus},
  1571. {"Combo Box", DrawComboBox},
  1572. {"Input", DrawInput},
  1573. {"Image", DrawImage},
  1574. {"Cursor", DrawCursor},
  1575. {"List Box", DrawListBox},
  1576. {"Tree", DrawTree},
  1577. {"Dialog", DrawDialog},
  1578. {"Interaction", DrawInteraction},
  1579. {"Shapes", DrawShapes},
  1580. {"Tooltips", DrawTooltip},
  1581. {"Stats", DrawStats},
  1582. {"Layout", DrawLayout},
  1583. {"Fonts", DrawFonts},
  1584. {"Tabs", DrawTab},
  1585. {"Dock", DrawDock}
  1586. }
  1587. local Selected = nil
  1588. function SlabTest.Begin()
  1589. local StatHandle = Slab.BeginStat('Slab Test', 'Slab Test')
  1590. SlabTest.MainMenuBar()
  1591. if Selected == nil then
  1592. Selected = Categories[1]
  1593. end
  1594. if DrawSlabTest then
  1595. Slab.BeginWindow('SlabTest', {Title = "Slab", AutoSizeWindow = false, W = 800.0, H = 600.0})
  1596. local W, H = Slab.GetWindowActiveSize()
  1597. if Slab.BeginComboBox('Categories', {Selected = Selected[1], W = W}) then
  1598. for I, V in ipairs(Categories) do
  1599. if Slab.TextSelectable(V[1]) then
  1600. Selected = Categories[I]
  1601. end
  1602. end
  1603. Slab.EndComboBox()
  1604. end
  1605. Slab.Separator()
  1606. if Selected ~= nil and Selected[2] ~= nil then
  1607. Selected[2]()
  1608. end
  1609. Slab.EndWindow()
  1610. end
  1611. SlabDebug.Begin()
  1612. Slab.EndStat(StatHandle)
  1613. end
  1614. return SlabTest