SlabTest.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 BasicWindow_Input = "This is some text!"
  24. local BasicWindow_Input_Numbers = 0
  25. local BasicWindow_CheckBox = false
  26. local BasicWindow_Options = {"Apple", "Banana", "Orange", "Pear", "Lemon"}
  27. local BasicWindow_Options_Selected = ""
  28. local BasicWindow_Properties =
  29. {
  30. X = 100.0,
  31. Y = 100.0,
  32. HasCollision = true,
  33. Name = "Player Name"
  34. }
  35. local BasicWindow_RadioButton = 1
  36. local ResetLayout = false
  37. local ListBoxIndex = 1
  38. local SlabTest_MessageBox = false
  39. local SlabTest_FileDialog = false
  40. local SlabTest_FileDialogType = 'openfile'
  41. local SlabTest_ColorPicker = false
  42. local SlabTest_ColorPicker_Color = {1.0, 1.0, 1.0, 1.0}
  43. function SlabTest.BasicWindow()
  44. Slab.BeginWindow('SlabTest_Basic', {Title = "Basic Window", X = 100.0, Y = 100.0, ResetLayout = ResetLayout})
  45. Slab.Text("Hello World!")
  46. if Slab.Button("Button!") then
  47. -- Perform logic here when button is clicked
  48. end
  49. if Slab.Button("Disabled!", {Disabled = true}) then
  50. end
  51. if Slab.BeginContextMenuItem() then
  52. Slab.MenuItem("Button Item 1")
  53. Slab.MenuItem("Button Item 2")
  54. Slab.EndContextMenu()
  55. end
  56. if Slab.Input('BasicWindow_Name', {Text = BasicWindow_Input}) then
  57. BasicWindow_Input = Slab.GetInputText()
  58. end
  59. if Slab.Input('BasicWindow_Numbers', {Text = tostring(BasicWindow_Input_Numbers), NumbersOnly = true, MinNumber = 100}) then
  60. BasicWindow_Input_Numbers = Slab.GetInputNumber()
  61. end
  62. Slab.Separator()
  63. if Slab.CheckBox(BasicWindow_CheckBox, "Check Box") then
  64. BasicWindow_CheckBox = not BasicWindow_CheckBox
  65. end
  66. if Slab.BeginComboBox('BasicWindow_Fruits', {Selected = BasicWindow_Options_Selected}) then
  67. for K, V in pairs(BasicWindow_Options) do
  68. if Slab.TextSelectable(V) then
  69. BasicWindow_Options_Selected = V
  70. end
  71. end
  72. Slab.EndComboBox()
  73. end
  74. if Slab.BeginContextMenuWindow() then
  75. Slab.MenuItem("BasicWindow Item 1")
  76. Slab.MenuItem("BasicWindow Item 2")
  77. Slab.MenuItem("BasicWindow Item 3")
  78. Slab.EndContextMenu()
  79. end
  80. Slab.Properties(BasicWindow_Properties)
  81. for I = 1, 4, 1 do
  82. if Slab.RadioButton("Radio " .. I, {Index = I, SelectedIndex = BasicWindow_RadioButton}) then
  83. BasicWindow_RadioButton = I
  84. end
  85. end
  86. Slab.Text("Is Void Hovered: " .. tostring(Slab.IsVoidHovered()))
  87. Slab.EndWindow()
  88. end
  89. function SlabTest.ResizableWindow()
  90. Slab.BeginWindow('SlabTest_Resizable', {Title = "Resizable Window", X = 350.0, Y = 100.0, AutoSizeWindow = false, ResetLayout = ResetLayout})
  91. Slab.Textf("This is a resizable window. This text will automatically wrap based on the window's dimensions.")
  92. Slab.NewLine()
  93. Slab.Textf("There is a new line separating these two texts.")
  94. Slab.EndWindow()
  95. end
  96. function SlabTest.TreeWindow()
  97. Slab.BeginWindow('SlabTest_Tree', {Title = "Tree Window", X = 600.0, Y = 100.0, AutoSizeWindow = false, ResetLayout = ResetLayout})
  98. if Slab.BeginTree('SlabTest_TreeRoot1', {Label = "Can be opened within rect", IconPath = SLAB_PATH .. "/Internal/Resources/Textures/Folder.png"}) then
  99. Slab.BeginTree('SlabTest_Child1_Leaf', {Label = "Leaf 1", IsLeaf = true})
  100. if Slab.BeginTree('SlabTest_Child1', {Label = "Child 1"}) then
  101. Slab.BeginTree('SlabTest_Child1_Leaf1', {Label = "Leaf 2", IsLeaf = true})
  102. Slab.BeginTree('SlabTest_Child1_Leaf2', {Label = "Leaf 3", IsLeaf = true})
  103. Slab.EndTree()
  104. end
  105. Slab.EndTree()
  106. end
  107. if Slab.BeginTree('SlabTest_TreeRoot2', {Label = "Only opened with arrow.", OpenWithHighlight = false}) then
  108. Slab.BeginTree('SlabTest_Child1_leaf', {Label = "Leaf 1", IsLeaf = true})
  109. Slab.EndTree()
  110. end
  111. local Path = "/Internal/Resources/Textures/power.png"
  112. local ImageOptions =
  113. {
  114. Path = SLAB_PATH .. Path,
  115. Scale = 0.5,
  116. Color = {1.0, 0.0, 0.0, 1.0},
  117. ReturnOnClick = true,
  118. Tooltip = "This is a sample image."
  119. }
  120. if Slab.Image('SlabTest_Image', ImageOptions) then
  121. -- Perform logic when clicked
  122. end
  123. Slab.BeginListBox('SlabTest_ListBox')
  124. for I = 1, 10, 1 do
  125. Slab.BeginListBoxItem('Item ' .. I, {Selected = I == ListBoxIndex})
  126. Slab.Text("Item " .. I)
  127. if Slab.IsListBoxItemClicked() then
  128. ListBoxIndex = I
  129. end
  130. Slab.EndListBoxItem()
  131. end
  132. Slab.EndListBox()
  133. Slab.Text("After List Box")
  134. Slab.EndWindow()
  135. end
  136. function SlabTest.MainMenuBar()
  137. if Slab.BeginMainMenuBar() then
  138. if Slab.BeginMenu("File") then
  139. if Slab.BeginMenu("New") then
  140. if Slab.MenuItem("File") then
  141. -- Create a new file.
  142. end
  143. if Slab.MenuItem("Project") then
  144. -- Create a new project.
  145. end
  146. Slab.EndMenu()
  147. end
  148. if Slab.MenuItem("Open") then
  149. SlabTest_FileDialog = true
  150. SlabTest_FileDialogType = 'openfile'
  151. end
  152. if Slab.MenuItem("Save") then
  153. SlabTest_FileDialog = true
  154. SlabTest_FileDialogType = 'savefile'
  155. end
  156. Slab.MenuItem("Save As")
  157. Slab.Separator()
  158. if Slab.MenuItem("Quit") then
  159. love.event.quit()
  160. end
  161. Slab.EndMenu()
  162. end
  163. if Slab.BeginMenu("Windows") then
  164. if Slab.MenuItem("Reset Layout") then
  165. ResetLayout = true
  166. end
  167. if Slab.MenuItemChecked("Message Box", SlabTest_MessageBox) then
  168. SlabTest_MessageBox = not SlabTest_MessageBox
  169. end
  170. if Slab.MenuItemChecked("Color Picker", SlabTest_ColorPicker) then
  171. SlabTest_ColorPicker = not SlabTest_ColorPicker
  172. end
  173. Slab.EndMenu()
  174. end
  175. SlabDebug.Menu()
  176. Slab.EndMainMenuBar()
  177. end
  178. end
  179. function SlabTest.GlobalContextMenu()
  180. if Slab.BeginContextMenuWindow() then
  181. Slab.MenuItem("Global Item 1")
  182. Slab.MenuItem("Global Item 2")
  183. Slab.MenuItem("Global Item 3")
  184. Slab.EndContextMenu()
  185. end
  186. end
  187. function SlabTest.Begin()
  188. SlabTest.MainMenuBar()
  189. SlabTest.BasicWindow()
  190. SlabTest.ResizableWindow()
  191. SlabTest.TreeWindow()
  192. SlabTest.GlobalContextMenu()
  193. ResetLayout = false
  194. if SlabTest_MessageBox then
  195. local Result = Slab.MessageBox("Test", "This is a test message box.")
  196. if Result ~= "" then
  197. SlabTest_MessageBox = false
  198. end
  199. end
  200. if SlabTest_FileDialog then
  201. local Result = Slab.FileDialog({Type = SlabTest_FileDialogType, Filters = {{"*.*", "All Files"}, {"*.lua", "Lua Files"}, {"*.txt", "Text Files"}}})
  202. if Result.Button ~= "" then
  203. print("Button: " .. Result.Button)
  204. print("Files: " .. #Result.Files)
  205. for I, V in ipairs(Result.Files) do
  206. print(" " .. V)
  207. end
  208. SlabTest_FileDialog = false
  209. end
  210. end
  211. if SlabTest_ColorPicker then
  212. local Result = Slab.ColorPicker({Color = SlabTest_ColorPicker_Color})
  213. if Result.Button ~= "" then
  214. SlabTest_ColorPicker = false
  215. if Result.Button == "OK" then
  216. SlabTest_ColorPicker_Color = Result.Color
  217. end
  218. end
  219. end
  220. SlabDebug.Begin()
  221. end
  222. return SlabTest