Skip to content

Instantly share code, notes, and snippets.

@cschomburg
Created June 9, 2010 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cschomburg/432133 to your computer and use it in GitHub Desktop.
Save cschomburg/432133 to your computer and use it in GitHub Desktop.
-- optionsTable
local frameStacks = {
["main"] = {
frames = {},
firstPos = { "RIGHT", UIParent, "RIGHT", -65, -85 },
nextPos = { "BOTTOM", "TOP", 0, 15 },
nextColPos = { "BOTTOMRIGHT", "BOTTOMLEFT", -15, 0 },
},
}
-- This anchors one frame in its stack
local function stackAnchorSingle(frame)
local stack = frame.stack
local frames = stack.frames
local height = frame:GetHeight() / frame:GetEffectiveScale()
local uiHeight = UIParent:GetHeight() / UIParent:GetEffectiveScale()
frame:ClearAllPoints()
frame.beginsCol = nil
local searchBeginning
for i=frame.stackPos-1, 1, -1 do
local prev = frames[i]
if(prev:IsShown()) then
if(searchBeginning) then
if(prev.beginsCol) then
-- This frame begins a new column, anchor next to it!
local a,b,c,d = unpack(stack.nextColPos)
frame.beginsRow = true
return frame:SetPoint(a, prev, b,c,d)
end
elseif(prev:GetTop() / prev:GetEffectiveScale() + height > uiHeight) then
-- Our frame wouldn't fit on this column, create a new one
searchBeginning = true
else
-- Just place on column
local a,b,c,d = unpack(stack.nextPos)
return frame:SetPoint(a, prev, b,c,d)
end
end
end
-- No previous frame found? Be the first then!
frame:SetPoint(unpack(stack.firstPos))
frame.beginsCol = true
end
-- This anchors a frame and the following ones
local function stackAnchorFrame(frame)
stackAnchorSingle(frame)
for i=frame.stackPos+1, #frameStacks[stackname].frames do
stackAnchorSingle(frame)
end
end
-- Anchors all frames in the stack
function stackAnchorAll(stackName)
for i,frame in ipairs(frameStacks[stackName].frames) do
stackAnchorSingle(frame)
end
end
-- Adds a frame to the stack
function addToStack(frame, stackName)
local stack = frameStacks[stackName]
table.insert(stack.frames, frame)
frame.stack = stack
frame.stackPos = #stack.frames
end
addToStack(MyFrame, "main")
MyFrame:SetScript("OnShow", stackAnchorFrame)
MyFrame:SetScript("OnHide", stackAnchorFrame)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment