Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: duncanx on November 18, 2013, 09:29:12 PM

Title: UITable Padding Setup and CenterOnChild delay
Post by: duncanx on November 18, 2013, 09:29:12 PM
So I have a completely dynamic UI. Must work on various sized devices (Android). To do that, I am often using anchors and stretches because they can function on relative space.

However, with tables the padding is in pixels instead of something relative so I've needed to write some code to step into the table at runtime and tweak things based on the device surface (after initialization, change padding sizes based on screen size and item size, which is also dynamic). So far so good. The issue comes whenever I try to do something very soon after the table gets enabled.

CenterOnChild for example. It's always a little "off". I noticed that if I just let it center itself twice, it would fix the error. Then I realized what's happening is that the padding updates just weren't quite finished. To fix this, all I've found so far is that I can delay the CenterOnChild for 0.2 seconds, then everything is fine. But that's so hacky and you can see the pause. I've tried narrowing in on the delay, but I worry I'll get timing issues on different devices. I wish I had some way of knowing precisely when I can call CenterOnChild, or if relative padding was built into the UITable.

Another solution I've thought of is silently enabling all the UI at once so these padding updates and various other fixes can "take" to the dynamic UI before I need to really display it (and before it needs to move correctly). That also feels like a hack though so I figure I'd post about it and see what others think.

ps: My feature request: Everything in NGUI that has a pixel setting, should also have a relative method of setting the same thing, and vice versa.
Title: Re: UITable Padding Setup and CenterOnChild delay
Post by: duncanx on November 19, 2013, 02:21:13 AM
I have this almost solved.

I don't know why I didn't think of it before...I'm just having the table adjustment script call the centeronchild method instead of the centeronchild calling itself on enable (it still calls itself on drag though). For springing panels this works perfectly. I still have one nagging issue that one of my panels, which needs to spring instantly (set to strength 1000), there is one frame where you can see it move around/adjust itself before it looks right.

I am happy enough with it now to move on, but later during polish phase I will probably want to fix up that one frame bit somehow.