This is what I've come up with. I ended up rewriting it from scratch while using the newer version's position calculation as it was cleaner and I had already made it configurable.
Lua Code:
-- Config Constants
local Aura_Size=21;
local Aura_Spacing=2;
local Aura_ShortCols=4;-- Buffs per short row
local Aura_ShortRows=2;-- Number of shortened rows
local Aura_NormalCols=6;-- Buffs per remaining rows
-- Calculated Constants
local Aura_ShortPadCols=Aura_NormalCols-Aura_ShortCols;
local Aura_GridSize=Aura_Size+Aura_Spacing;
local function ReanchorAuras(self,auratype,container,prevrows)
prevrows=prevrows or 0;
local nameformat=("%s%s%%d"):format(self:GetName(),auratype);
local point,relframe,relpoint,offsetx,offsety;
local rowcount,lastrowanchor=prevrows,nil;
for i=1,math.huge do-- Trick into running an infinite counter loop
local auraframe=_G[nameformat:format(i)];
if not (auraframe and auraframe:IsShown()) then return rowcount,lastrowanchor; end-- We're done, return here
if i>1 then
local posindex=i-1; if not self.buffsOnTop and prevrows<Aura_ShortRows then
posindex=posindex+math.min(math.floor(posindex/Aura_ShortCols),Aura_ShortRows-prevrows)*Aura_ShortPadCols;
end
local x,y=posindex%Aura_NormalCols,math.floor(posindex/Aura_NormalCols);
auraframe:SetPoint(point,relframe,relpoint
,x*Aura_GridSize+offsetx
,(self.buffsOnTop and 1 or -1)*y*Aura_GridSize+offsety
);
if x==0 then
rowcount,lastrowanchor=prevrows+y+1,auraframe;
container:SetPoint(relpoint,auraframe,relpoint,0,self.buffsOnTop and 1 or -1);
end
else point,relframe,relpoint,offsetx,offsety=auraframe:GetPoint(1); end
-- Note: DebuffType border scales with size, but Stealable border doesn't
auraframe:SetSize(Aura_Size,Aura_Size);
local stealborder=_G[nameformat:format(i).."Stealable"]; if stealborder then
local size=math.floor(Aura_Size*8/7);
stealborder:SetSize(size,size);
end
end
end
hooksecurefunc("TargetFrame_UpdateAuras",function(self)
local rowcount,anchor1,anchor2=0,nil,nil;
if UnitIsFriend("player",self.unit) then
rowcount,anchor1=ReanchorAuras(self,"Buff",self.buffs,rowcount);
rowcount,anchor2=ReanchorAuras(self,"Debuff",self.debuffs,rowcount);
else
rowcount,anchor1=ReanchorAuras(self,"Debuff",self.debuffs,rowcount);
rowcount,anchor2=ReanchorAuras(self,"Buff",self.buffs,rowcount);
end
self.auraRows=rowcount;
self.spellbarAnchor=anchor1 or anchor2;
end);