What does it do?
It handles the basic code for creating a scrollList & updating the scrollList data for you.
How do I create a scrollList with it?
I will give a full example at the end of this post, first lets look at the individual pieces of code you need.
At the top of your code file load the library:
Lua Code:
local libScroll = LibStub:GetLibrary("LibScroll")
You will need to create a table containing the necessary information for initializing your scrollList. Below is an example containing all possible information you may include. Only the name, parent, & setupCallback are necessary, the rest are optional.
ScrollData table:
Warning: Spoiler
Lua Code:
local scrollData ={
name ="MyTestScrollList",
parent = EmoteItWin,
width =300,
height =500,
rowHeight =23,
rowTemplate ="EmoteItRowControlTemplate",
setupCallback = setupDataRow,
sortFunction = SortScrollList,
selectTemplate ="EmoteItSelectTemplate",
selectCallback = OnRowSelection,
dataTypeSelectSound = SOUNDS.BOOK_CLOSE,
hideCallback = OnRowHide,
resetCallback = OnRowReset,
categories ={1, 2},
}
Then just call:
Lua Code:
local scrollList = libScroll:CreateScrollList(scrollData)
Explanation of table items:
Warning: Spoiler
Required Values:
name -- A unique name for your scrollList control
parent -- The parent control for your scrollList
setupCallback -- The function that will be called when each row control becomes visible.
Optional Values:
(optional) categories -- A table containing the integer values for your categories. Categories allow you to add items to the list with different categories & then you can show or hide groups of items based on their category ID without needing to clear & reload the scrollList with new data.
(optional) dataTypeSelectSound -- An optional sound to play when a row is selected.
(optional) height -- The height of your scrollList. If not supplied the default is 400.
(optional) hideCallback -- An optional callback that fires when the row control gets hidden.
(optional) resetControlCallback -- An optional callback when the row control gets reset.
(optional) rowHeight -- The height for the rows in your scrollList. If not supplied the default is 30
(optional) rowTemplate -- The name of the virtual control template that will be used to hold this data. If not supplied the default is ZO_SelectableLabel
(optional) selectCallback -- The function that will be called when a data item is selected. NOTE: This does not fire when clicking on the item in the scrollList without you providing additional code (see complete example below with selectionCallback).
(optional) selectTemplate -- The template for the selected item (highlight). There is no default. This is to allow users to leave this value out if they want a selection callback without highlights. If you want highlights & don't know what to use, use "ZO_ThinListHighlight"
(optional) sortFunction -- The function that will be called to sort your scrollList. There is no default, if left out the list will be unsorted.
(optional) width -- The width of your scrollList. If not supplied the default is 250.
Create your table of dataItems to be loaded into the scrollList:
You do not have to use "name" the tables can contain any data you want.
categoryId is optional, it is used to group items together in categories so you can show/hide items by showing/hiding categories.
Lua Code:
local dataItems ={
[1]={name ="first"},
[2]={name ="second", categoryId =2},
[3]={name ="third", categoryId =2},
[4]={name ="fourth", categoryId =2},
[5]={name ="fifth", categoryId =3},
[6]={name ="sixth", categoryId =3},
[7]={name ="seventh", categoryId =7},
[8]={name ="eigth", categoryId =8},
[9]={name ="nineth", categoryId =9},
}
Then just call Update and pass in your table:
Lua Code:
scrollList:Update(dataItems)
Available Functions:
scrollList:Clear() -- Clears all data from the scrollList
scrollList:Update (table dataItems) -- Pass in a table containing all of your data items for the scrollList to update the list with new data.
** Do note for the show/hide category functions to work the category values must be assigned to the scrollList by including them in the scrollData table that you pass to libScroll:CreateScrollList(scrollData) **
** Also these will only effect data items that have a categoryId assigned to them. As an example if you did not assign a categoryId to a data item & call HideAllCategories it will not be hidden **
scrollList:ShowAllCategories() -- Shows all data items that have a categoryId that matches one of the categories assigned to the scrollList. Data items without a categoryId will not be effected.
scrollList:ShowOnlyCategory(integer categoryId) -- Shows only data items that have the given categoryId, all other data items are hidden (if they have a categoryId, items without a categoryId will not be effected).
scrollList:ShowCategory(integer categoryId) -- Shows data items that have the given categoryId.
scrollList:HideAllCategories() -- Hides all data items that have a categoryId that matches one of the categories assigned to the scrollList. Data items without a categoryId will not be effected.
scrollList:HideCategory(integer categoryId) -- Hides data items that have the given categoryId.
A Complete (simple) example for creating a scrollList, no highlights, no select callbacks, & no sorting:
Warning: Spoiler
Lua Code:
local ADDON_NAME ="TestAddon"
TestAddon = ZO_Object:New()
local libScroll = LibStub:GetLibrary("LibScroll")
-- This function creates a top level window to hold our scrollList
localfunction CreateMainWindow()
-- Create a top level window:
local tlw = WINDOW_MANAGER:CreateTopLevelWindow("TestScrollList")