Pull Alt Currency frame out into its own file

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ
2016-09-09 00:52:50 -06:00
parent b608e8804b
commit 79f543afa0
6 changed files with 102 additions and 45 deletions

33
externals/size_to_fit.lua vendored Normal file
View File

@ -0,0 +1,33 @@
local myname, ns = ...
-- Resize a frame to fit all its visible children. Useful for creating frames
-- that adjust to their contents while reducing couping between those frames
--
-- Attach to a frame by using `frame.SizeToFit = ns.SizeToFit`. Call with colon
-- syntax, i.e. `frame:SizeToFit()` on the eldest frame you want to resize.
-- All children with this helper will be resized if they are currently shown.
local function ResizeChildren(...)
for i=1,select("#", ...) do
local child = select(i, ...)
if child.SizeToFit and child:IsShown() then child:SizeToFit() end
end
end
function ns.SizeToFit(self)
-- The frame must be visible for `GetBoundsRect()` to work. That means it has
-- to be "Shown" and have non-zero dimensions
self:Show()
self:SetSize(1, 1)
-- Child frames need to be resized first
ResizeChildren(self:GetChildren())
-- Now resize ourself
local _, _, width, height = self:GetBoundsRect()
self:SetSize(width, height)
end