Page 1 of 1

[solved]VerticalLayoutContainer:getUnclippedOuterRect()

Posted: Wed Jan 12, 2011 11:33
by spracle
For VerticalLayoutContainer,if you do something like this:

Code: Select all

(VerticalLayoutContainer *)vcPtr->removeChildAtPosition(2);
rect = vcPtr->getUnclippedOuterRect();

you'll get wrong answer.The size of rect is previous,before removeChildWindow.

Later,I did something like this:

Code: Select all

(vcPtr->setPosition(pos);
rect = vcPtr->getUnclippedOuterRect();

then,the rect is right;

Problem's that i need to get the right 'rect' to locate the right position for itself.

Anyone could help? Thanks first :)

Re: VerticalLayoutContainer:getUnclippedOuterRect(), a bug?

Posted: Wed Jan 12, 2011 11:40
by spracle
By the way , i called the function "layout()" between "romove(or add)ChildWindow" and "getUnclippedOuterRect()",and it 's not working all the same.

Re: VerticalLayoutContainer:getUnclippedOuterRect(), a bug?

Posted: Wed Jan 12, 2011 12:31
by Kulik
What are you expecting as the "right" rect? IIRC layout containers return their parent's clip rectangles.

Re: VerticalLayoutContainer:getUnclippedOuterRect(), a bug?

Posted: Thu Jan 13, 2011 01:46
by spracle
layoutContainer:
A ----------- B
| (child_1) |
C----------- D
| (child_2) |
--------------
| (child_3) |
E------------F

When getUnclippedOuterRect(),the result should be ABEF;
when removeChildWindow(child_1),then result should be CDEF;

Hope I figured it out clearly

Re: VerticalLayoutContainer:getUnclippedOuterRect(), a bug?

Posted: Thu Jan 13, 2011 13:26
by Kulik
Layout containers only delegate inner rect to their parent, so I don't know why outer rect is broken. I will redo layout containers (hopefully) for 0.8 so I will look into this later.

For now I would go with getPosition and getPixelSize. The size is updated every time layout() is called. And layout() is called as late as possible for performance reasons, so after you remove a child, call layout() manually and then construct the rect from getPosition() (convert it to absolute via CoordConverter if necessary) and getSize()

Re: VerticalLayoutContainer:getUnclippedOuterRect(), a bug?

Posted: Fri Jan 14, 2011 02:34
by spracle
By the way , i called the function "layout()" between "romove(or add)ChildWindow" and "getUnclippedOuterRect()",and it 's not working all the same.

--Sorry about this,it works, so outer rect isn't broken

My Problem was that VerticalLayoutContainer had one chlid whose type is VerticalLayoutContainer with some children attached on it.For this child, I removed its children, but called it's parent's layout()! sigh~

The correct behaviour is to call itself layout(),and then call its parent's layout(), and then getUnclippedOuterRect();

So,now the forcus is when layout() is called. I don't think that after removing child ,just markNeedtoLayout(),and when update(),the layout() is called automaticly is a good idea.
Obviously,if you don't call layout() manually between "removeChild"and "getUnclippedOuterRect", you'll get the wrong Rect.
If you call layout() manually ,next time update() is called, the layout() will be automatic called again,which is not necessary.

Re: VerticalLayoutContainer:getUnclippedOuterRect(), a bug?

Posted: Fri Jan 14, 2011 02:48
by Kulik
Imagine you would remove 10 children at once, if it was implemented as you suggest, layout() would be called 10 times. If you want the rect up to date quicker, just call layoutIfNecessary, it will mark that the layouting has been done and no mroe layouting will happen in update()

Re: VerticalLayoutContainer:getUnclippedOuterRect(), a bug?

Posted: Fri Jan 14, 2011 06:52
by spracle
layoutIfNecessary instead of layout is pretty cool .
My point is that ,if you don't call the function layoutIfNecessary() manually between removeChild() and getUnclippedOuterRect(),you will not get the right rect ten to one
kind of weird..

Anyway,thanks kulik,you are very helpful~