Updated List (markdown)

Robert Jelic
2022-04-02 12:56:56 +02:00
parent db7dde712e
commit 5eea57d618

140
List.md

@@ -1 +1,139 @@
WIP
Lists are objects where you can create endless entrys and the user can choose one of them
Here is a example of how to create a standard list:
````lua
local mainFrame = NyoUI.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):
## addItem
Adds a item to the list
````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)
````
**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>
## removeItem
Removes a item to the list
````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:removeItem(2)
````
**args:** item table (you can get with :getValue()) OR item index<br>
**returns:** the object<br>
## setActiveItemBackground
Sets the background of the item which is currently selected
````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:setActiveItemBackground(colors.green)
````
**args:** any color<br>
**returns:** the object<br>
## setActiveItemForeground
Sets the foreground of the item which is currently selected
````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:setActiveItemForeground(colors.red)
````
**args:** any color<br>
**returns:** the object<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
````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:setItemColors(colors.red,colors.blue)
````
**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)
````