Thread Tools Display Modes
07-14-12, 01:20 PM   #1
Gregity
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 54
Auto-resize frame

If I have a frame that composed of other frames is it possible to have the outer frame adjust based upon the size of the inner frames?

Let's say I have 1 outer frame with three inner frames A, B, C. A sets relative to the parent, B relative to A, and C relative to B.

Is there a way to set the parent's bottom right to the bottom right of C? Such that if A, B, or C grow then the parent will grow?

Also, what happens in the event that one (or more) of the inner frames gets hidden?

-g
  Reply With Quote
07-14-12, 01:49 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You can call as many :SetPoint()s as you want. You can anchor topleft and bottomright for example. This is the main reason why it's very important to call :ClearAllPoints() before :SetPoint().

As for when a frame gets hidden, that entirely depends on how you code the placement of your frames in the event that something is not shown.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-14-12, 02:40 PM   #3
Gregity
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 54
Parent
A - topleft to topleft of parent
B - topleft to bottomleft of A
C - topleft to bottomleft of B
Parent - bottomleft to bottomleft of C ??

I want A to track with the Parent, but I want the size of parent to track with bottomleft of C.

Once I've set all the points, if I then change the size of "B" then does the parent frame adjust size?

Upon hiding the "B" frame, does that break the chain or does it count as a zero size? Is it as if its topleft = its bottomleft? (That would be great)

-g
  Reply With Quote
07-14-12, 06:31 PM   #4
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Originally Posted by Gregity View Post
Parent
A - topleft to topleft of parent
B - topleft to bottomleft of A
C - topleft to bottomleft of B
Parent - bottomleft to bottomleft of C ??

I want A to track with the Parent, but I want the size of parent to track with bottomleft of C.

Once I've set all the points, if I then change the size of "B" then does the parent frame adjust size?

Upon hiding the "B" frame, does that break the chain or does it count as a zero size? Is it as if its topleft = its bottomleft? (That would be great)

-g
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 so, then what you have will work. Note also that you will have to manually set the heights of all three frames, since there's nothing in the chain that tells them how big to be.

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).

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.


Now, if you want A and B to resize as well when the parent resizes, then you start with the same basic setup, give all three child frames fixed heights, and then in your resize function you include instructions to set the height of each child frame to some multiple of the height of the parent frame.

Last edited by kaels : 07-14-12 at 06:36 PM.
  Reply With Quote
07-14-12, 11:23 PM   #5
Gregity
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 54
Actually I was hoping resizing any of them will cause the parent to resize.

However if having something get hidden will break the works then means that I have to have a resize function so I can just calc the size based upon that (and reset parents and whatnot).

I was just hoping I could be lazy...

Thanks for the comments
-g
  Reply With Quote
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
07-14-12, 11:38 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Gregity View Post
Actually I was hoping resizing any of them will cause the parent to resize.
You could do that too, but you would have to do it manually.

Alternatively, if C is positioned relative to B, and B is positioned relative to A, then you could position A relative to the UIParent, and then position the parent frame relative to the TOPLEFT of A and the BOTTOMRIGHT of C.

Originally Posted by Gregity View Post
However if having something get hidden will break the works then means that I have to have a resize function so I can just calc the size based upon that (and reset parents and whatnot).
Hiding something will not break anything, as long as your frames are correctly parented. In this example, A, B, and C should all be direct children of F -- not children of each other. However, unless you manually reposition C after you hide B, you will have an empty space between A and B.

Honestly, though, all of this vague "A, B, and C" stuff makes it really hard to give you good suggestions and code. Why don't you just describe what you actually want to do?
__________________
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
07-14-12, 11:56 PM   #8
Gregity
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 54
Thanks

Phanx, thanks for being so patient and clear with your answers.

Yes, A, B, C, are all children of F. My appologies if I said or implied anything to the contrary. No automatic sizing of A, B, or C - Their sizing will be manual. I was only interested in F resizing. I did not mention horizontal sizing as they will all be the same width.

If hiding B causes a gap to appear unless I reset the points, then I need to reset the points. Needing to reset the points means I need code to do that and that is not a problem - just didn't want to write code that may have been superfluous.

Thank you again for your help, I've got a pretty good idea what to do now.

-g
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Auto-resize frame

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off