Go to Page... |
Compatibility: | Flames of Ambition (6.3.5) Markarth (6.2.5) |
Updated: | 02/17/21 02:26 AM |
Created: | 07/19/15 06:24 PM |
Monthly downloads: | 1,411 |
Total downloads: | 133,086 |
Favorites: | 18 |
MD5: |
At the top of your code file load the library:Create the ScrollList
Lua Code:
local libScroll = 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.Update the scrollList with your data
ScrollData table example:
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}, }
Explanation of table items:
Warning: Spoiler
Required Values:name -- A unique name for your scrollList controlOptional Values:
parent -- The parent control for your scrollList (not GuiRoot)
setupCallback -- The function that will be called when each row control becomes visible.
(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 -- The function that will be called when the row control gets hidden.
(optional) resetControlCallback -- The function that will be called 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.
Then just call:
Lua Code:
local scrollList = libScroll:CreateScrollList(scrollData)
Create your table of dataItems to be loaded into the scrollList. Then just call Update and pass in your table:That is all there is to it.
Lua Code:
scrollList:Update(dataItems)
dataItems table example:
The table for each individual data item can contain any data you want, this is only an example.
categoryId is optional, it is used to group items together in categories so you can show/hide groups of items by showing/hiding their categoryId.
Warning: Spoiler
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}, }
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 that do not have a categoryId that matches one of the scrollList categories 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 that do not have a categoryId that matches one of the scrollList categories will not be effected.
scrollList:HideCategory(integer categoryId) -- Hides data items that have the given categoryId.
local ADDON_NAME = "TestAddon" local libScroll = LibScroll -- This function creates a top level window to hold our scrollList local function CreateMainWindow() -- Create a top level window: local tlw = WINDOW_MANAGER:CreateTopLevelWindow("TestScrollList") tlw:SetAnchor(CENTER, GuiRoot, CENTER) tlw:SetDimensions(300, 250) -- create a background for it (optional) tlw.bg = WINDOW_MANAGER:CreateControlFromVirtual("TestScrollListBg", tlw, "ZO_DefaultBackdrop") tlw.bg:SetAnchorFill() return tlw end -- Create the row setup callback function local function SetupDataRow(rowControl, data, scrollList) -- Do whatever you want/need to setup the control rowControl:SetText(data.name) rowControl:SetFont("ZoFontWinH4") end -- Function that creates the scrollList local function CreateScrollList() local mainWindow = CreateMainWindow() -- Create the scrollData table for your scrollList local scrollData = { name = "EmoteScrollListTest", parent = mainWindow, width = 200, height = 150, rowHeight = 23, setupCallback = SetupDataRow, } -- Call the libraries CreateScrollList local scrollList = libScroll:CreateScrollList(scrollData) -- Anchor it however you want scrollList:SetAnchor(TOPLEFT, mainWindow, TOPLEFT, 50, 50) -- create the tables for your scrollLists data items local dataItems = { [1] = {name = "first"}, [2] = {name = "second"}, [3] = {name = "third"}, [4] = {name = "fourth"}, [5] = {name = "fifth"}, [6] = {name = "sixth"}, [7] = {name = "seventh"}, [8] = {name = "eigth"}, [9] = {name = "nineth"}, } -- Call Update to add the data items to the scrollList scrollList:Update(dataItems) end ------------------------------------------------------------------- -- OnAddOnLoaded -- ------------------------------------------------------------------- local function OnAddOnLoaded(event, addonName) if addonName ~= ADDON_NAME then return end -- Create the scrollList local scrollList = CreateScrollList() EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED) end --------------------------------------------------------------------- -- Register Events -- --------------------------------------------------------------------- EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, OnAddOnLoaded)
local ADDON_NAME = "TestAddon" local libScroll = LibScroll -- This function gathers information about emotes to -- be placed in our scrollList. You can get your data -- from wherever local function GetScrollData() local dataItems = {} for emoteIndex=1, GetNumEmotes() do local emoteSlashName, emoteCategory, emoteId = GetEmoteInfo(emoteIndex) -- Organize your data for each item inside of a table local data = { emoteName = string.sub(emoteSlashName,2), emoteId = emoteId, emoteIndex = emoteIndex, categoryId = emoteCategory, } -- and use table.insert to put them into the dataItems table table.insert(dataItems, data) end return dataItems end -- This function creates a top level window to hold our scrollList local function CreateMainWindow() -- Create a top level window: local tlw = WINDOW_MANAGER:CreateTopLevelWindow("TestScrollList") tlw:SetAnchor(CENTER, GuiRoot, CENTER) tlw:SetDimensions(300, 400) -- create a background for it (optional) tlw.bg = WINDOW_MANAGER:CreateControlFromVirtual("TestScrollListBg", tlw, "ZO_DefaultBackdrop") tlw.bg:SetAnchorFill() return tlw end -- Create the row selection function (if needed) local function OnRowSelect(previouslySelectedData, selectedData, reselectingDuringRebuild) if not selectedData then return end d("Now playing emote: "..selectedData.emoteName) PlayEmoteByIndex(selectedData.emoteIndex) end -- Create the sort function (if needed) local function SortScrollList(objA, objB) return objA.data.emoteName < objB.data.emoteName end -- Create the row setup callback function local function SetupDataRow(rowControl, data, scrollList) -- Do whatever you want/need to setup the control rowControl:SetText(data.emoteName) rowControl:SetFont("ZoFontWinH4") rowControl:SetHandler("OnMouseUp", function() ZO_ScrollList_MouseClick(scrollList, rowControl) end) end -- Function that creates the scrollList local function CreateScrollList() -- Creates the top level window to hold our scrollList local mainWindow = CreateMainWindow() -- Create the scrollData table for your scrollList local scrollData = { name = "EmoteScrollListTest", parent = mainWindow, width = 200, height = 300, rowHeight = 23, setupCallback = SetupDataRow, selectCallback = OnRowSelect, dataTypeSelectSound = SOUNDS.BOOK_CLOSE, sortFunction = SortScrollList, } -- Call the libraries CreateScrollList local scrollList = libScroll:CreateScrollList(scrollData) -- Anchor it however you want scrollList:SetAnchor(TOPLEFT, mainWindow, TOPLEFT, 50, 50) return scrollList end local function InitializeScrollList() -- Create the scrollList local scrollList = CreateScrollList() -- Get your data from wherever & update the scrollList local scrollData = GetScrollData() scrollList:Update(scrollData) end ------------------------------------------------------------------- -- OnAddOnLoaded -- ------------------------------------------------------------------- local function OnAddOnLoaded(event, addonName) if addonName ~= ADDON_NAME then return end InitializeScrollList() EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED) end --------------------------------------------------------------------- -- Register Events -- --------------------------------------------------------------------- EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, OnAddOnLoaded)
Comment Options |
Baertram |
View Public Profile |
Send a private message to Baertram |
Find More Posts by Baertram |
Add Baertram to Your Buddy List |
02/17/21, 04:10 AM | |
|
Thank you!
Thank you for updating.
I just needed to understand how UI controls work, so these samples are very helpful. |
|
Calamath |
View Public Profile |
Send a private message to Calamath |
Find More Posts by Calamath |
Add Calamath to Your Buddy List |
07/20/15, 08:02 AM | |
|
Sweet
LOL I guess you got tired of answering my questions about scrolllists =P
This will help someone greatly I am sure! |
|
kerb9729 |
View Public Profile |
Send a private message to kerb9729 |
Find More Posts by kerb9729 |
Add kerb9729 to Your Buddy List |