View Single Post
07-14-12, 11:34 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by kaels View Post
This is somewhat confusing. Basically, as far as I can tell, you want 3 vertically-stacked frames, aligned on the left side, all on top of a single background (the parent), and you want to be able to resize the parent and C (but not A and B) by moving the bottom left corner of the whole thing.
If you have parent frame F containing child frames A, B, and C:

Code:
A:ClearAllPoints()
A:SetPoint("TOPLEFT", F, "TOPLEFT", 0, 0)
A:SetPoint("TOPRIGHT", F, "TOPRIGHT", 0, 0)
A:SetHeight(20)

B:ClearAllPoints()
B:SetPoint("TOPLEFT", A, "BOTTOMLEFT", 0, 0)
B:SetPoint("TOPRIGHT", A, "BOTTOMRIGHT", 0, 0)
B:SetHeight(20)

C:ClearAllPoints()
C:SetPoint("TOPLEFT", B, "BOTTOMLEFT", 0, 0)
C:SetPoint("TOPRIGHT", B, "BOTTOMRIGHT", 0, 0)
C:SetPoint("BOTTOM", F, "BOTTOM", 0, 0)

F:SetWidth(100)
-- F, A, B, and C are all now 100 units wide.

F:SetHeight(60)
-- A, B, and C are each 20 units high.

F:SetHeight(100)
-- A and B are each 20 units high. C is 60 units high.
Since the heights of A and B are hardcoded via :SetHeight, their height will not change when the height of F changes. Since the height of C is not hardcoded, and is determined dynamically by its anchor points, its height will change when the height of F changes.

Note that you will get undesired/undefined behavior if you set the height of F to less than the height of A + the height of B + 0, since that would define the height of C as less than 0.

If you want all three children to split the height equally, then you would have to specify them all explicitly. You could easily automate this by hooking the :SetHeight method on F:

Code:
A:ClearAllPoints()
A:SetPoint("TOPLEFT", F, "TOPLEFT", 0, 0)
A:SetPoint("TOPRIGHT", F, "TOPRIGHT", 0, 0)

B:ClearAllPoints()
B:SetPoint("TOPLEFT", A, "BOTTOMLEFT", 0, 0)
B:SetPoint("TOPRIGHT", A, "BOTTOMRIGHT", 0, 0)

C:ClearAllPoints()
C:SetPoint("TOPLEFT", B, "BOTTOMLEFT", 0, 0)
C:SetPoint("TOPRIGHT", B, "BOTTOMRIGHT", 0, 0)
C:SetPoint("BOTTOM", F, "BOTTOM", 0, 0)

local F_SetHeight = F.SetHeight
function F:SetHeight(height)
	F_SetHeight(height)
	A:SetHeight(height / 3)
	B:SetHeight(height / 3)
	C:SetHeight(height / 3)
end

F:SetHeight(60)
-- A, B, and C are now each 20 units high.
Originally Posted by kaels View Post
Changing the height of B will change the height of the parent (it will move the bottom edge of B, which will move the bottom edge of C).
The parent should not be anchored relative to any of its children, and in many cases trying to do so will result in an error. For example, if you anchor the TOPLEFT point of A to the TOPLEFT point of B, set a height and width on A, and then try to anchor the BOTTOMRIGHT of B to the BOTTOMRIGHT of A, you will get an error. You should always maintain a clear heirarchy in both parenting and anchoring.

Originally Posted by kaels View Post
Hiding B will not have good results. I'm not 100% sure, but I believe C will disappear because it's no longer anchored to anything. You will need to manually re-anchor the topleft of C to the bottomleft of A.
Incorrect. You can freely position visible frames relative to hidden frames. The only way hiding A will also hide C is if C is a child of A -- eg. you did C:SetParent(A) or C = CreateFrame("Frame", "FrameC", A). Positional relationships are completely independent of parent/child relationships.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote