Updated List (markdown)

Robert Jelic
2022-05-02 20:54:14 +02:00
parent b5047db7cd
commit 21422fa5f1

152
List.md

@@ -3,137 +3,121 @@ Lists are objects where you can create endless entrys and the user can choose on
Here is a example of how to create a standard list:
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
````
This will create a default list with the size 8 width and 5 height on position 1 1 (relative to its parent frame), the default background is colors.lightGray, the default text color is colors.black and the default zIndex is 5. The default horizontal text align is "center", default symbol is ">"
Here are all possible functions available for lists. Remember list inherit from [object](https://github.com/NoryiE/NyoUI/wiki/Object):
Here are all possible functions available for lists. Remember list inherit from [object](https://github.com/NoryiE/basalt/wiki/Object):
## addItem
Adds a item to the list
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList: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.<br>
**returns:** the object<br>
**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)<br>
**returns:** self<br>
## removeItem
Removes a item to the list
Removes a item from the list
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:removeItem(2)
````
**args:** item table (you can get with :getValue()) OR item index<br>
**returns:** the object<br>
**parameters:** number index<br>
**returns:** self<br>
## setActiveItemBackground
## editItem
Edits a item on the list
````lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:editItem(3,"3. Edited Entry",colors.yellow,colors.green)
````
**parameters:** number index, string text, number bgcolor, number fgcolor, any ...<br>
**returns:** self<br>
## setScrollable
Makes the list scrollable
````lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setScrollable(true)
````
**parameters:** boolean isScrollable<br>
**returns:** self<br>
## selectItem
selects a item in the list (same as a player would click on a item)
````lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:selectItem(1)
````
**parameters:** number index<br>
**returns:** self<br>
## 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 aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setActiveItemBackground(colors.green)
aList:setSelectedItem(colors.green, colors.blue)
````
**args:** any color<br>
**returns:** the object<br>
**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)<br>
**returns:** self<br>
## setActiveItemForeground
Sets the foreground of the item which is currently selected
## setOffset
sets the list offset (will automatically change if scrolling is active)
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setActiveItemForeground(colors.red)
aList:setOffset(3)
````
**args:** any color<br>
**returns:** the object<br>
**parameters:** number offsetValue<br>
**returns:** self<br>
## 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 aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setItemColors(colors.red,colors.blue)
aList:getOffset()
````
**args:** any color - multiple colors possible<br>
**returns:** the object<br>
## 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
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setItemTextColors(colors.blue,colors.red)
````
**args:** any color - multiple colors possible<br>
**returns:** the object<br>
## addScrollbar
adds a scrollbar to be able to scroll trough the list without mouse_scroll
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:addScrollbar(aScrollbar)
````
**args:** scrollbar object<br>
**returns:** the object<br>
## setSymbol
sets the symbol of the selected item before text
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setSymbol(" ")
````
**args:** you can choose any symbol, if you dont want a symbol just set it to ""<br>
**returns:** the object<br>
# Examples
Get the selected item informations:
````lua
local mainFrame = NyoUI.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:onChange(function(self)
NyoUI.debug(self:getValue().text,self:getValue().bgcolor,self:getValue().fgcolor,self:getValue().vars)
end)
````
**parameters:** -<br>
**returns:** number offsetValue<br>