I agree that ideally it should be like that. Unfortunately the way panels work was set in stone many years ago, and even the eventual creation of UIRect in an attempt to optimize some of the common functionality was done years later. You can still use the common functionality via the UIRect's SetRect() function, set anchors the same way on both panels and widgets, and some other things, but there is a pretty big difference between panels and widgets that's not going to disappear due to backwards compatibility.
If I was to re-design it, throwing backwards compatibility to the wind, I'd do it differently. If I do NGUI for the Unreal Engine I will do just that. But this part of NGUI for Unity is not likely to change.
That's really unfortunate. I sure hope the new UI-Engine for Unity 4.x doesn't get polluted with this, since as I understand NGUI has a vital part in that, yes? "Open for extension, closed for modification" is key in OOP (not trying to lecture you but more push on the importance).
Anyways, I noticed another very annoying issue with nested panels (A scrollview with a nested panel as child). Keeping the story short the issue lies in that UIRect is abstract and not the "true" base class for a UI frame, so I have to chose wether to have a UIPanel as the "rect", or a UIWidget. Problem is, I really need it to be a UIPanel and I naturally use the frame as bounds to know when cells should be put pack on the reusable stack (it's a custom made table with reusable cells to be able to have "infinite" cells in the table). Now, if the user wants the table can auto expand to fully enclose all cells, and in this case the bounds from the NEXT UIPanel with clipping turned on should be used to know if cells are visible or not.
So I have this (simplified for this example since this is the use case causing the bug):
- ScrollView A (with UIPanel attached)
-- Panel A
--- UIWidget (cell)
--- UIWidget (cell)
--- etc.
Now, if I activate cells when they become visible (using UIScrollViews bounds), they will be rendered in the wrong position (even though positioned correctly).
So I do this:
- Drag scrollView (fast/release it out of bounds to let it spring back)
- While dragging, enable widgets inside Panel A (child panel)
- Watch the widget being render incorrectly, and a force-refresh of Panel A is needed
Since this only happens while ACTIVATING a widget inside a child panel while DRAGGING the parent-panel, one might conclude that the problem lies in the offset of ScrollView A's panel messing up the drawing of child-panel A.
That's a mouthful, but you should get the picture. To temporarily fix it, I added the possibility for UIPanel.Find to ignore panels if disabled and a boolean "IgnoreIfDisabled" is set to true. Thanks to this the panel being scrolled will also be responsible for drawing my cells, and the offset won't mess it up.
Thanks!