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:
local panel = CreateFrame("Frame", "ResizablePanel", UIParent, "SecureFrameTemplate")
-- Shortcut
panel.Execute = SecureHandlerExecute
panel.SetFrameRef = SecureHandlerSetFrameRef
panel.WrapScript = function (self, frame, script, preBody, postBody)
SecureHandlerWrapScript(frame, script, self, preBody, postBody)
end
-- Grid Settings
panel:SetAttribute("WIDTH", 100) -- Unit Frame width
panel:SetAttribute("HEIGHT", 48) -- Unit Frame height
panel:SetAttribute("HSPACE", 2) -- horizontal spacing
panel:SetAttribute("VSPACE", 2) -- vertical spacing
panel:SetAttribute("ROWCNT", 5) -- Row counts
panel:SetAttribute("COLCNT", 4) -- Col counts
panel:Execute[[
Manager = self -- keep self to avoid some bug, I don't know if it still existed
_UnitFrames = newtable() -- where we keep all unit frames
UpdatePanelSize = [=[
-- For simple, skip several settings like margin, orientation
local rowcnt = Manager:GetAttribute("ROWCNT")
local colcnt = Manager:GetAttribute("COLCNT")
local width = Manager:GetAttribute("WIDTH")
local height = Manager:GetAttribute("HEIGHT")
local vspace = Manager:GetAttribute("VSPACE")
local hspace = Manager:GetAttribute("HSPACE")
local count = 0
-- Re-position unit frames based on visiblity
for i = 1, #_UnitFrames do
local frm = _UnitFrames[i]
if frm:IsShown() then
-- orientation is vertical first
local posX = (floor(count / rowcnt)) * (width + hspace)
local posY = (count % rowcnt) * (height + vspace)
frm:SetWidth(width)
frm:SetHeight(height)
frm:ClearAllPoints()
-- from top to bottom
frm:SetPoint("TOP", Manager, "TOP", 0, - posY)
-- from left to right
frm:SetPoint("LEFT", Manager, "LEFT", posX, 0)
count = count + 1
end
end
-- Re-size the Manager
local maxcol = ceil(count / rowcnt)
local maxrow = maxcol == 1 and count or rowcnt
if maxrow > 0 and maxcol > 0 then
Manager:SetWidth(maxcol * width + (maxcol - 1) * hspace)
Manager:SetHeight(maxrow * height + (maxrow - 1) * vspace)
else
-- You also can use Hide here
Manager:SetWidth(1)
Manager:SetHeight(1)
end
]=]
]]
-- For simple I generate those unit frames directly
-- Your is generated by the ouf
for i = 1, panel:GetAttribute("ROWCNT") do
for j = i , panel:GetAttribute("COLCNT") do
local unitframe = CreateFrame("Button", "ResizablePanel_" .. i .. "_" .. j, panel, "SecureActionButtonTemplate")
-- Register the unitframe
panel:SetFrameRef("unitframe", unitframe)
panel:Execute[[tinsert(_UnitFrames, Manager:GetFrameRef("unitframe"))]]
-- Wrap the unitframe's show/hide
-- So the secure UpdatePanelSize can be run based on the unitframe's visiblity
panel:WrapScript(unitframe, "OnShow", [[Manager:RunFor(self, UpdatePanelSize)]])
panel:WrapScript(unitframe, "OnHide", [[Manager:RunFor(self, UpdatePanelSize)]])
end
end
-- Force updating
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.