Thread: Trying to Learn
View Single Post
06-29-19, 10:55 AM   #27
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
And to package the table into a really ugly (but hopefully visual concept wise) no xml (on your part) scroll list for display (use sorting from fusionpit to add sort buttons):

Lua Code:
  1. local classes = { "Rogue", "Paladin", "Mage", "Warlock", "Priest", "DK", "DH", "Hunter", "Shaman", "Druid", "Monk", "Warrior" }
  2.  
  3. local width, height, numrows = 200, 20, 6
  4.  
  5. local TableData = {}
  6.  
  7. for i=1, 30 do
  8.     tinsert(TableData, { player=i, class=random(1, #classes), dkp=random(0, 10000) })
  9. end
  10.  
  11. local function OnClick(self)
  12.     print(self:GetText())
  13. end
  14.  
  15. local function CreateRow(parent, id) -- Create 3 buttons for each row in the list
  16.     local f = CreateFrame("Frame", "$parentLine"..id, parent)
  17.     f.Buttons = {}
  18.     f:SetSize(width, height)
  19.     for i=1, 3 do
  20.         tinsert(f.Buttons, CreateFrame("Button", "$parentButton"..i, f, "UIPanelButtonTemplate"))
  21.         f.Buttons[i]:SetSize(width/3, height)
  22.         f.Buttons[i]:SetPoint("LEFT", f.Buttons[i-1] or f, f.Buttons[i-1] and "RIGHT" or "LEFT")
  23.         f.Buttons[i]:SetScript("OnClick", OnClick)
  24.     end
  25.     return f
  26. end
  27.  
  28. local function MyFrame_Update(self)
  29.     local numOptions = #TableData
  30.     local index, row
  31.     local offset = FauxScrollFrame_GetOffset(self)
  32.     for i=1, numrows do
  33.         row = self.Rows[i]
  34.         index = offset + i
  35.         if TableData[index] then
  36.             row:Show()
  37.             row.index = index
  38.             row.Buttons[1]:SetText("Player"..TableData[index].player)
  39.             row.Buttons[2]:SetText(classes[TableData[index].class])
  40.             row.Buttons[3]:SetText(TableData[index].dkp)
  41.         else
  42.             row:Hide()
  43.         end
  44.     end
  45.     FauxScrollFrame_Update(self, numOptions, numrows, height)
  46. end
  47.  
  48. local f = CreateFrame("ScrollFrame", "FizzleScrollFrame", UIParent, "FauxScrollFrameTemplate")
  49. f:SetSize(width, height*numrows)
  50. f:SetPoint("LEFT", 20, 0)
  51. f.Rows = {}
  52. for i=1, numrows do
  53.     f.Rows[i] = CreateRow(f, i)
  54.     f.Rows[i]:SetPoint("TOPLEFT", f.Rows[i-1] or f, f.Rows[i-1] and "BOTTOMLEFT" or "TOPLEFT")
  55. end
  56. f:SetScript("OnVerticalScroll", function(self, offset)
  57.     FauxScrollFrame_OnVerticalScroll(self, offset, height, MyFrame_Update)
  58. end)
  59. MyFrame_Update(f)

You could make each row a single button with 3 FontStrings or ...
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-29-19 at 02:41 PM.
  Reply With Quote