Back to Home

ESO Lua File v100025

libraries/zo_parametricgridlist/zo_abstractsingletemplategridscrolllist.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
----------------------
-- ZO_AbstractSingleTemplateGridScrollList
----------------------
ZO_GRID_SCROLL_LIST_AUTOFILL = true
ZO_GRID_SCROLL_LIST_DONT_AUTOFILL = false
ZO_AbstractSingleTemplateGridScrollList = ZO_AbstractGridScrollList:Subclass()
function ZO_AbstractSingleTemplateGridScrollList:New(...)
    return ZO_AbstractGridScrollList.New(self, ...)
end
function ZO_AbstractSingleTemplateGridScrollList:Initialize(control, autofillRows)
    ZO_AbstractGridScrollList.Initialize(self, control)
    self.controlsAddedSinceLastFill = 0
    self.autoFillRows = autofillRows or false
end
function ZO_AbstractSingleTemplateGridScrollList:SetHeaderTemplate(templateName, height, setupFunc, onHideFunc, resetControlFunc)
    self.headerOperationId = self:AddHeaderTemplate(templateName, height, setupFunc, onHideFunc, resetControlFunc)
end
function ZO_AbstractSingleTemplateGridScrollList:SetGridEntryTemplate(templateName, width, height, setupFunc, onHideFunc, resetControlFunc, spacingX, spacingY, centerEntries)
    self.entryOperationId = self:AddEntryTemplate(templateName, width, height, setupFunc, onHideFunc, resetControlFunc, spacingX, spacingY, centerEntries)
    self:RefreshEmptyCellData(width, spacingX)
end
function ZO_AbstractSingleTemplateGridScrollList:RefreshEmptyCellData(width, spacingX)
    local listWidth = self.list:GetWidth()
    local numCellsPerRow = zo_floor(listWidth / (width + spacingX))
    self.numCellsPerRow = numCellsPerRow
end
function ZO_AbstractSingleTemplateGridScrollList:AddEntry(data)
    local gridHeaderName = data.gridHeaderName
    if self.currentHeaderName ~= gridHeaderName then
        local scrollData = ZO_ScrollList_GetDataList(self.list)
        if self.currentHeaderName or #scrollData > 0 then
            -- we're starting a new section, so first make sure to fill out the last row of the previous section
            self:FillRowWithEmptyCells()
            ZO_ScrollList_AddOperation(self.list, ZO_SCROLL_LIST_OPERATION_LINE_BREAK, { lineBreakAmount = self.lineBreakAmount })
        end
        self.currentHeaderName = gridHeaderName
        if self.currentHeaderName and self.currentHeaderName ~= "" then
            ZO_ScrollList_AddOperation(self.list, self.headerOperationId, { header = gridHeaderName, data = data })
        end
    end
    ZO_ScrollList_AddOperation(self.list, self.entryOperationId, data)
    self.controlsAddedSinceLastFill = self.controlsAddedSinceLastFill + 1
end
function ZO_AbstractSingleTemplateGridScrollList:FillRowWithEmptyCells()
    if self.autoFillRows then
        local numMissingCells = self.numCellsPerRow - zo_mod(self.controlsAddedSinceLastFill, self.numCellsPerRow)
        if numMissingCells ~= self.numCellsPerRow then -- the row was full, don't need to add any empty cells
            for i = 1, numMissingCells do
                ZO_ScrollList_AddOperation(self.list, self.entryOperationId, { isEmptyCell = true })
            end
        end
    end
    self.controlsAddedSinceLastFill = 0
end
function ZO_AbstractSingleTemplateGridScrollList:CommitGridList()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    if #scrollData > 0 then -- only try to fill in a row if there exists a row to fill in
        self:FillRowWithEmptyCells()
    end
    ZO_AbstractGridScrollList.CommitGridList(self)
    self.controlsAddedSinceLastFill = 0
end