From 5a74473ffd136665fef5bda71f49d39bab887703 Mon Sep 17 00:00:00 2001
From: Robert Jelic <36573031+NoryiE@users.noreply.github.com>
Date: Mon, 2 May 2022 21:02:48 +0200
Subject: [PATCH] Updated Dropdown (markdown)
---
Dropdown.md | 202 +++++++++++++++++++++++++++++++++++-----------------
1 file changed, 135 insertions(+), 67 deletions(-)
diff --git a/Dropdown.md b/Dropdown.md
index 781ed9a..6325181 100644
--- a/Dropdown.md
+++ b/Dropdown.md
@@ -1,110 +1,178 @@
-Dropdowns are objects which looks like a button, but as soon as you click on them, they will open a dropdown where you can choose a value. But first you will have to add possible values
+Dropdowns are objects where you can create endless entrys the user can click on a button and it opens a "list" where the user can choose a entry
Here is a example of how to create a standard dropdown:
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
````
-This will create a default dropdown with the size 5 width and 1 height on position 1 1 (relative to its parent frame), the default background is colors.lightBlue, the default text color is colors.black and the default zIndex is 10. The default horizontal text align is "center"
-
-Here are all possible functions available for dropdowns. Remember dropdown inherit from [object](https://github.com/NoryiE/NyoUI/wiki/Object):
+Here are all possible functions available for dropdowns:
+Remember dropdown inherits from [object](https://github.com/NoryiE/basalt/wiki/Object):
## addItem
-Adds a item to the list
+Adds a item to the dropdown
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropDown:addItem("1. Entry")
-aDropDown:addItem("2. Entry",colors.yellow)
-aDropDown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
````
-**args:** text, bgcolor, fgcolor, ..., text is the displayed text, bgcolor and fgcolors the colors of background/text and args (...) is something dynamic, you wont see them but if you require some more information per item you can use that.
-**returns:** the object
+**parameters:** string text, number bgcolor, number fgcolor, any ... - (text is the displayed text, bgcolor and fgcolors the colors of background/text and args (...) is something dynamic, you wont see them but if you require some more information per item you can use that)
+**returns:** self
## removeItem
-Removes a item to the list
+Removes a item from the dropdown
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropDown:addItem("1. Entry")
-aDropDown:addItem("2. Entry",colors.yellow)
-aDropDown:addItem("3. Entry",colors.yellow,colors.green)
-aDropDown:removeItem(2)
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:removeItem(2)
````
-**args:** item table (you can get with :getValue()) OR item index
-**returns:** the object
+**parameters:** number index
+**returns:** self
-## setActiveItemBackground
+## editItem
+Edits a item on the dropdown
+
+````lua
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:editItem(3,"3. Edited Entry",colors.yellow,colors.green)
+````
+**parameters:** number index, string text, number bgcolor, number fgcolor, any ...
+**returns:** self
+
+## setScrollable
+Makes the dropdown scrollable
+
+````lua
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:setScrollable(true)
+````
+**parameters:** boolean isScrollable
+**returns:** self
+
+## selectItem
+selects a item in the dropdown (same as a player would click on a item)
+
+````lua
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:selectItem(1)
+````
+**parameters:** number index
+**returns:** self
+
+## clear
+clears the entire list (dropdown)
+
+````lua
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:clear()
+````
+**parameters:** -
+**returns:** self
+
+## getItemIndex
+returns the item index of the currently selected item
+
+````lua
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
+local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:getItemIndex()
+````
+**parameters:** -
+**returns:** number index
+
+## setSelectedItem
Sets the background of the item which is currently selected
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropDown:addItem("1. Entry")
-aDropDown:addItem("2. Entry",colors.yellow)
-aDropDown:addItem("3. Entry",colors.yellow,colors.green)
-aDropDown:setActiveItemBackground(colors.green)
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:setSelectedItem(colors.green, colors.blue)
````
-**args:** any color
-**returns:** the object
+**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)
+**returns:** self
-## setActiveItemForeground
-Sets the foreground of the item which is currently selected
+## setOffset
+sets the dropdown offset (will automatically change if scrolling is active)
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropDown:addItem("1. Entry")
-aDropDown:addItem("2. Entry",colors.yellow)
-aDropDown:addItem("3. Entry",colors.yellow,colors.green)
-aDropDown:setActiveItemForeground(colors.red)
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:setOffset(3)
````
-**args:** any color
-**returns:** the object
+**parameters:** number offsetValue
+**returns:** self
-## setItemColors
-Sets item background colors in the list
-you can set as many colors as you want, it will set one color per line, if it got to the last color it will go back to the first color
+## getOffset
+returns the current offset
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropDown:addItem("1. Entry")
-aDropDown:addItem("2. Entry",colors.yellow)
-aDropDown:addItem("3. Entry",colors.yellow,colors.green)
-aDropDown:setItemColors(colors.red,colors.blue)
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:getOffset()
````
-**args:** any color - multiple colors possible
-**returns:** the object
+**parameters:** -
+**returns:** number offsetValue
-## setItemTextColors
-Sets item text colors in the list
-you can set as many colors as you want, it will set one color per line, if it got to the last color it will go back to the first color
+## getOffset
+returns the current offset
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropDown:addItem("1. Entry")
-aDropDown:addItem("2. Entry",colors.yellow)
-aDropDown:addItem("3. Entry",colors.yellow,colors.green)
-aDropDown:setItemTextColors(colors.blue,colors.red)
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:getOffset()
````
-**args:** any color - multiple colors possible
-**returns:** the object
+**parameters:** -
+**returns:** number offsetValue
+
+## setDropdownSize
+sets the dropdown size (if you click on the button)
-# Examples
-Get the selected item informations:
````lua
-local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
+local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
-aDropDown:addItem("1. Entry")
-aDropDown:addItem("2. Entry",colors.yellow)
-aDropDown:addItem("3. Entry",colors.yellow,colors.green)
-aDropDown:onChange(function(self)
-NyoUI.debug(self:getValue().text,self:getValue().bgcolor,self:getValue().fgcolor,self:getValue().vars)
-end)
-````
\ No newline at end of file
+aDropdown:addItem("1. Entry")
+aDropdown:addItem("2. Entry",colors.yellow)
+aDropdown:addItem("3. Entry",colors.yellow,colors.green)
+aDropdown:setDropdownSize(12, 4)
+````
+**parameters:** number width, number height
+**returns:** self
\ No newline at end of file