123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- --[[
- MIT License
- Copyright (c) 2019 Mitchell Davis <coding.jackalope@gmail.com>
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- --]]
- local Slab = require('Slab')
- local SlabDebug = require(SLAB_PATH .. '.SlabDebug')
- local SlabTest = {}
- local BasicWindow_Input = "This is some text!"
- local BasicWindow_Input_Numbers = 0
- local BasicWindow_CheckBox = false
- local BasicWindow_Options = {"Apple", "Banana", "Orange", "Pear", "Lemon"}
- local BasicWindow_Options_Selected = ""
- local BasicWindow_Properties =
- {
- X = 100.0,
- Y = 100.0,
- HasCollision = true,
- Name = "Player Name"
- }
- local BasicWindow_RadioButton = 1
- local ResetLayout = false
- local ListBoxIndex = 1
- local SlabTest_MessageBox = false
- local SlabTest_FileDialog = false
- local SlabTest_FileDialogType = 'openfile'
- local SlabTest_ColorPicker = false
- local SlabTest_ColorPicker_Color = {1.0, 1.0, 1.0, 1.0}
- function SlabTest.BasicWindow()
- Slab.BeginWindow('SlabTest_Basic', {Title = "Basic Window", X = 100.0, Y = 100.0, ResetLayout = ResetLayout})
- Slab.Text("Hello World!")
- if Slab.Button("Button!") then
- -- Perform logic here when button is clicked
- end
- if Slab.Button("Disabled!", {Disabled = true}) then
- end
- if Slab.BeginContextMenuItem() then
- Slab.MenuItem("Button Item 1")
- Slab.MenuItem("Button Item 2")
- Slab.EndContextMenu()
- end
- if Slab.Input('BasicWindow_Name', {Text = BasicWindow_Input}) then
- BasicWindow_Input = Slab.GetInputText()
- end
- if Slab.Input('BasicWindow_Numbers', {Text = tostring(BasicWindow_Input_Numbers), NumbersOnly = true, MinNumber = 100}) then
- BasicWindow_Input_Numbers = Slab.GetInputNumber()
- end
- Slab.Separator()
- if Slab.CheckBox(BasicWindow_CheckBox, "Check Box") then
- BasicWindow_CheckBox = not BasicWindow_CheckBox
- end
- if Slab.BeginComboBox('BasicWindow_Fruits', {Selected = BasicWindow_Options_Selected}) then
- for K, V in pairs(BasicWindow_Options) do
- if Slab.TextSelectable(V) then
- BasicWindow_Options_Selected = V
- end
- end
- Slab.EndComboBox()
- end
- if Slab.BeginContextMenuWindow() then
- Slab.MenuItem("BasicWindow Item 1")
- Slab.MenuItem("BasicWindow Item 2")
- Slab.MenuItem("BasicWindow Item 3")
- Slab.EndContextMenu()
- end
- Slab.Properties(BasicWindow_Properties)
- for I = 1, 4, 1 do
- if Slab.RadioButton("Radio " .. I, {Index = I, SelectedIndex = BasicWindow_RadioButton}) then
- BasicWindow_RadioButton = I
- end
- end
- Slab.Text("Is Void Hovered: " .. tostring(Slab.IsVoidHovered()))
- Slab.EndWindow()
- end
- function SlabTest.ResizableWindow()
- Slab.BeginWindow('SlabTest_Resizable', {Title = "Resizable Window", X = 350.0, Y = 100.0, AutoSizeWindow = false, ResetLayout = ResetLayout})
- Slab.Textf("This is a resizable window. This text will automatically wrap based on the window's dimensions.")
- Slab.NewLine()
- Slab.Textf("There is a new line separating these two texts.")
- Slab.EndWindow()
- end
- function SlabTest.TreeWindow()
- Slab.BeginWindow('SlabTest_Tree', {Title = "Tree Window", X = 600.0, Y = 100.0, AutoSizeWindow = false, ResetLayout = ResetLayout})
-
- if Slab.BeginTree('SlabTest_TreeRoot1', {Label = "Can be opened within rect", IconPath = SLAB_PATH .. "/Internal/Resources/Textures/Folder.png"}) then
- Slab.BeginTree('SlabTest_Child1_Leaf', {Label = "Leaf 1", IsLeaf = true})
- if Slab.BeginTree('SlabTest_Child1', {Label = "Child 1"}) then
- Slab.BeginTree('SlabTest_Child1_Leaf1', {Label = "Leaf 2", IsLeaf = true})
- Slab.BeginTree('SlabTest_Child1_Leaf2', {Label = "Leaf 3", IsLeaf = true})
- Slab.EndTree()
- end
- Slab.EndTree()
- end
- if Slab.BeginTree('SlabTest_TreeRoot2', {Label = "Only opened with arrow.", OpenWithHighlight = false}) then
- Slab.BeginTree('SlabTest_Child1_leaf', {Label = "Leaf 1", IsLeaf = true})
- Slab.EndTree()
- end
-
- local Path = "/Internal/Resources/Textures/power.png"
- local ImageOptions =
- {
- Path = SLAB_PATH .. Path,
- Scale = 0.5,
- Color = {1.0, 0.0, 0.0, 1.0},
- ReturnOnClick = true,
- Tooltip = "This is a sample image."
- }
- if Slab.Image('SlabTest_Image', ImageOptions) then
- -- Perform logic when clicked
- end
-
- Slab.BeginListBox('SlabTest_ListBox')
- for I = 1, 10, 1 do
- Slab.BeginListBoxItem('Item ' .. I, {Selected = I == ListBoxIndex})
- Slab.Text("Item " .. I)
- if Slab.IsListBoxItemClicked() then
- ListBoxIndex = I
- end
- Slab.EndListBoxItem()
- end
- Slab.EndListBox()
- Slab.Text("After List Box")
- Slab.EndWindow()
- end
- function SlabTest.MainMenuBar()
- if Slab.BeginMainMenuBar() then
- if Slab.BeginMenu("File") then
- if Slab.BeginMenu("New") then
- if Slab.MenuItem("File") then
- -- Create a new file.
- end
- if Slab.MenuItem("Project") then
- -- Create a new project.
- end
- Slab.EndMenu()
- end
- if Slab.MenuItem("Open") then
- SlabTest_FileDialog = true
- SlabTest_FileDialogType = 'openfile'
- end
- if Slab.MenuItem("Save") then
- SlabTest_FileDialog = true
- SlabTest_FileDialogType = 'savefile'
- end
- Slab.MenuItem("Save As")
- Slab.Separator()
- if Slab.MenuItem("Quit") then
- love.event.quit()
- end
- Slab.EndMenu()
- end
- if Slab.BeginMenu("Windows") then
- if Slab.MenuItem("Reset Layout") then
- ResetLayout = true
- end
- if Slab.MenuItemChecked("Message Box", SlabTest_MessageBox) then
- SlabTest_MessageBox = not SlabTest_MessageBox
- end
- if Slab.MenuItemChecked("Color Picker", SlabTest_ColorPicker) then
- SlabTest_ColorPicker = not SlabTest_ColorPicker
- end
- Slab.EndMenu()
- end
- SlabDebug.Menu()
- Slab.EndMainMenuBar()
- end
- end
- function SlabTest.GlobalContextMenu()
- if Slab.BeginContextMenuWindow() then
- Slab.MenuItem("Global Item 1")
- Slab.MenuItem("Global Item 2")
- Slab.MenuItem("Global Item 3")
- Slab.EndContextMenu()
- end
- end
- function SlabTest.Begin()
- SlabTest.MainMenuBar()
- SlabTest.BasicWindow()
- SlabTest.ResizableWindow()
- SlabTest.TreeWindow()
- SlabTest.GlobalContextMenu()
- ResetLayout = false
- if SlabTest_MessageBox then
- local Result = Slab.MessageBox("Test", "This is a test message box.")
- if Result ~= "" then
- SlabTest_MessageBox = false
- end
- end
- if SlabTest_FileDialog then
- local Result = Slab.FileDialog({Type = SlabTest_FileDialogType, Filters = {{"*.*", "All Files"}, {"*.lua", "Lua Files"}, {"*.txt", "Text Files"}}})
- if Result.Button ~= "" then
- print("Button: " .. Result.Button)
- print("Files: " .. #Result.Files)
- for I, V in ipairs(Result.Files) do
- print(" " .. V)
- end
- SlabTest_FileDialog = false
- end
- end
- if SlabTest_ColorPicker then
- local Result = Slab.ColorPicker({Color = SlabTest_ColorPicker_Color})
- if Result.Button ~= "" then
- SlabTest_ColorPicker = false
- if Result.Button == "OK" then
- SlabTest_ColorPicker_Color = Result.Color
- end
- end
- end
- SlabDebug.Begin()
- end
- return SlabTest
|