SlabTest.lua 57 KB

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