View Single Post
09-22-17, 05:06 AM   #4
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
My codes is here, it's an interface so I used it for raid panel and bag containers.

Here is a simple one, I don't do a test, since the group header settings is ignored :

Lua Code:
  1. local panel = CreateFrame("Frame", "ResizablePanel", UIParent, "SecureFrameTemplate")
  2.  
  3. -- Shortcut
  4. panel.Execute = SecureHandlerExecute
  5. panel.SetFrameRef = SecureHandlerSetFrameRef
  6. panel.WrapScript = function (self, frame, script, preBody, postBody)
  7.     SecureHandlerWrapScript(frame, script, self, preBody, postBody)
  8. end
  9.  
  10. -- Grid Settings
  11. panel:SetAttribute("WIDTH", 100)    -- Unit Frame width
  12. panel:SetAttribute("HEIGHT", 48)    -- Unit Frame height
  13. panel:SetAttribute("HSPACE", 2)     -- horizontal spacing
  14. panel:SetAttribute("VSPACE", 2)     -- vertical spacing
  15. panel:SetAttribute("ROWCNT", 5)     -- Row counts
  16. panel:SetAttribute("COLCNT", 4)     -- Col counts
  17.  
  18. panel:Execute[[
  19.     Manager = self  -- keep self to avoid some bug, I don't know if it still existed
  20.  
  21.     _UnitFrames = newtable()  -- where we keep all unit frames
  22.  
  23.     UpdatePanelSize = [=[
  24.         -- For simple, skip several settings like margin, orientation
  25.         local rowcnt = Manager:GetAttribute("ROWCNT")
  26.         local colcnt = Manager:GetAttribute("COLCNT")
  27.         local width  = Manager:GetAttribute("WIDTH")
  28.         local height = Manager:GetAttribute("HEIGHT")
  29.         local vspace = Manager:GetAttribute("VSPACE")
  30.         local hspace = Manager:GetAttribute("HSPACE")
  31.  
  32.         local count  = 0
  33.  
  34.         -- Re-position unit frames based on visiblity
  35.         for i = 1, #_UnitFrames do
  36.             local frm = _UnitFrames[i]
  37.             if frm:IsShown() then
  38.                 -- orientation is vertical first
  39.                 local posX = (floor(count / rowcnt)) * (width + hspace)
  40.                 local posY = (count % rowcnt) * (height + vspace)
  41.  
  42.                 frm:SetWidth(width)
  43.                 frm:SetHeight(height)
  44.                 frm:ClearAllPoints()
  45.        
  46.                 -- from top to bottom
  47.                 frm:SetPoint("TOP", Manager, "TOP", 0, - posY)
  48.  
  49.                 -- from left to right
  50.                 frm:SetPoint("LEFT", Manager, "LEFT", posX, 0)
  51.  
  52.                 count = count + 1
  53.             end
  54.         end
  55.  
  56.         -- Re-size the Manager
  57.         local maxcol = ceil(count / rowcnt)
  58.         local maxrow = maxcol == 1 and count or rowcnt
  59.  
  60.         if maxrow > 0 and maxcol > 0 then
  61.             Manager:SetWidth(maxcol * width + (maxcol - 1) * hspace)
  62.             Manager:SetHeight(maxrow * height + (maxrow - 1) * vspace)
  63.         else
  64.             -- You also can use Hide here
  65.             Manager:SetWidth(1)
  66.             Manager:SetHeight(1)
  67.         end
  68.     ]=]
  69. ]]
  70.  
  71. -- For simple I generate those unit frames directly
  72. -- Your is generated by the ouf
  73. for i = 1, panel:GetAttribute("ROWCNT") do
  74.     for j = i , panel:GetAttribute("COLCNT") do
  75.         local unitframe = CreateFrame("Button", "ResizablePanel_" .. i .. "_" .. j, panel, "SecureActionButtonTemplate")
  76.        
  77.         -- Register the unitframe
  78.         panel:SetFrameRef("unitframe", unitframe)
  79.         panel:Execute[[tinsert(_UnitFrames, Manager:GetFrameRef("unitframe"))]]
  80.  
  81.         -- Wrap the unitframe's show/hide
  82.         -- So the secure UpdatePanelSize can be run based on the unitframe's visiblity
  83.         panel:WrapScript(unitframe, "OnShow", [[Manager:RunFor(self, UpdatePanelSize)]])
  84.         panel:WrapScript(unitframe, "OnHide", [[Manager:RunFor(self, UpdatePanelSize)]])
  85.     end
  86. end
  87.  
  88. -- Force updating
  89. Manager:Execute[[Manager:Run(UpdatePanelSize)]]

Also there is a topic discuss about Run secure code based on the group header system, you can find my answer from #12.

I don't know if it can be combined with the Ouf, you may have a try.
  Reply With Quote