You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.4 KiB
101 lines
2.4 KiB
|
5 years ago
|
local WIT, core = ...
|
||
|
|
|
||
|
|
local AceGUI = LibStub("AceGUI-3.0")
|
||
|
|
|
||
|
|
local GridColumns = core.GridColumns
|
||
|
|
|
||
|
|
function GridColumns.GridColumn(name)
|
||
|
|
local self = {
|
||
|
|
Visible = true,
|
||
|
|
Name = name,
|
||
|
|
DisplayName = core.GetString(name),
|
||
|
|
Sortable = true
|
||
|
|
}
|
||
|
|
|
||
|
|
function self.Value(data)
|
||
|
|
return 0
|
||
|
|
end
|
||
|
|
|
||
|
|
function self.GetCell(row)
|
||
|
|
local cell = AceGUI:Create("Label")
|
||
|
|
|
||
|
|
cell:SetText(self.GetRowText(row))
|
||
|
|
|
||
|
|
return cell
|
||
|
|
end
|
||
|
|
|
||
|
|
function self.IsVisible()
|
||
|
|
return self.Visible
|
||
|
|
end
|
||
|
|
|
||
|
|
function self.IsSortable()
|
||
|
|
return self.Sortable
|
||
|
|
end
|
||
|
|
|
||
|
|
function self.GetSortValue(row)
|
||
|
|
row[self.Name] = row[self.Name] or self.Value(row.Data)
|
||
|
|
|
||
|
|
return row[self.Name] or 0
|
||
|
|
end
|
||
|
|
|
||
|
|
function self.GetRowText(row)
|
||
|
|
row[self.Name] = row[self.Name] or self.Value(row.Data)
|
||
|
|
|
||
|
|
return row[self.Name] or ''
|
||
|
|
end
|
||
|
|
|
||
|
|
function self.GetColumnMinWidth(rows)
|
||
|
|
local label = AceGUI:Create("Label")
|
||
|
|
label:SetText(self.DisplayName or self.Name)
|
||
|
|
|
||
|
|
local maxWidth = label.label:GetStringWidth() + 5
|
||
|
|
|
||
|
|
for _, row in pairs(rows) do
|
||
|
|
label:SetText(self.GetRowText(row))
|
||
|
|
local width = label.label:GetStringWidth() + 5
|
||
|
|
|
||
|
|
if width > maxWidth then
|
||
|
|
maxWidth = width
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
label:Release()
|
||
|
|
|
||
|
|
return maxWidth
|
||
|
|
end
|
||
|
|
|
||
|
|
function self.GetHeaderCell(onClickHandler)
|
||
|
|
local container = AceGUI:Create("SimpleGroup")
|
||
|
|
local cell = AceGUI:Create("InteractiveLabel")
|
||
|
|
|
||
|
|
cell:SetText(self.DisplayName or self.Name)
|
||
|
|
cell:SetWidth(cell.label:GetStringWidth() + 5)
|
||
|
|
|
||
|
|
if self.Description then
|
||
|
|
cell:SetCallback("OnEnter", function()
|
||
|
|
GameTooltip:SetOwner(cell.frame, "ANCHOR_PRESERVE")
|
||
|
|
GameTooltip:ClearAllPoints()
|
||
|
|
GameTooltip:SetPoint("LEFT", cell.frame, "RIGHT")
|
||
|
|
GameTooltip:ClearLines()
|
||
|
|
GameTooltip:AddLine(self.Description)
|
||
|
|
GameTooltip:Show()
|
||
|
|
end)
|
||
|
|
cell:SetCallback("OnLeave", function()
|
||
|
|
GameTooltip:Hide()
|
||
|
|
end)
|
||
|
|
end
|
||
|
|
|
||
|
|
cell:SetCallback("OnClick", function()
|
||
|
|
if onClickHandler then
|
||
|
|
onClickHandler(self)
|
||
|
|
end
|
||
|
|
end)
|
||
|
|
|
||
|
|
container:AddChild(cell)
|
||
|
|
|
||
|
|
return container
|
||
|
|
end
|
||
|
|
|
||
|
|
return self
|
||
|
|
end
|