Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: KevDK on December 16, 2013, 10:46:00 AM
-
Hey there,
I've started using NGUI recently, and while most things work as expected, I was surprised that there's no anchoring for the Grid - the anchoring works really great for all the other components.
Here's my situation: I have an area of my screen that is dedicated to a Scrollview. This Scrollview takes up 50% - 120 pixels in width, and 50% - 90 pixels in height. So the Scrollview changes very much depending on the screen size. Inside this Scrollview, I have a Grid. This grid should cover the entire Scrollview area, and be anchored in the top left corner of the Scrollview (so that the content is showed inside the Scrollview, and the grid is always positioned correctly). The problems currently arise with the Grid, as the position of the Grid is not fixed in any way - it seems to adapt to the content instead of the other way around. How can I anchor the grid, so it's always relative to the Scrollview's top-left position, unrelated to the screen size? That way, the content of the Grid could be inserted when the Grid is correctly placed.
The Anchor is legacy, and I haven't tried working with it before, so it seems pointless to try and integrate something that's deprecated. I've tried putting an invisible Widget (UIWidget) between the ScrollView and the Grid (which would then be anchored to the top-left corner of the ScrollView). That does position the Grid correctly, but then the Scrollview can't scroll anymore. It's like it keeps updating the view and resetting the scroll position, which in turn makes it stay where it is. I've toyed around with some other setups, but none of them work for me. A bit of help would be greatly appreciated :)
-
Have you seen the updated Drag & Drop example? It features not one but two scroll views anchored to screen height, with grids inside them.
-
I've now roughly copied the setup from that example, and while it works, it still feels a bit weird to work with.
In case someone else runs into the problem with positioning a grid, here's how I've made it work:
Container
|-- ScrollView
|-- Grid
|-- GridElement
|-- GridElement
The Container has a UIWidget have a top-left pivot. Make this be the size that the ScrollView should cover
The ScrollView is a default Scrollview. Ensure that the Scrollview's local Position is (0,0,0).
The Grid's local position should be (0,0,0) as well. This should ensure the Grid starts in the correct position on runtime, and that it doesn't jump around when the grid becomes empty and then filled up again.
The GridElements are Sprites that have a top-left pivot.
If anyone has a better setup, I'd really like to hear it, but this is what I'm going with for now.