Author Topic: UILabel bouncing when text updated  (Read 388 times)

malo88

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
UILabel bouncing when text updated
« on: May 15, 2017, 04:18:58 AM »
Hello,
I have a problem when updating the text of UILabels. I currently have 10 labels placed sequentially one after another (anchored right to each other) horizontally. The "Overflow" value is set to "Resize Freely" and that is the source of the problem, since that when is deactivated everything works. The problem is that when the text of the labels gets updated, the result is a sort of unwanted bouncing (or shaking, if you want) animation. It seems that the rectangle of the label containing the text is continuously resizing for a bit, and that causes this bad visual effect. Any solution for this, please?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 316
  • -Receive: 1149
  • Posts: 22,027
  • Toronto, Canada
    • View Profile
Re: UILabel bouncing when text updated
« Reply #1 on: May 19, 2017, 05:02:43 AM »
Have you tried using a UITable instead of anchoring? Seems to me you need to update all the labels' text, and only then do your positioning. I'm not sure about your set up and what order everything is set up in, but using a UITable here might just fix your issue.

malo88

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UILabel bouncing when text updated
« Reply #2 on: May 19, 2017, 05:59:06 AM »
Thanks for the answer! Let me explain a bit more my situation: I have ten UIWidgets in a row, one after another. Every Widget is anchored to the one at its right. Inside (so a child) every widget there is a UILabel, anchored to the right inside of it. So I was able to figure out the problem: since I am changing all the labels in one frame, updating all the text inside, it modifies the size of the labels and so, also the size of the widgets which have to reanchor to each other. What NGUI does is to postpone the update of the anchors in every frame (so it does not do that in a single frame), because it does not want to freeze the framerate if the reanchoring takes too long. This behaviour is causing this bouncing effect, because the reanchoring and resizing happens from right to left for every widget continously until they are all updated. So my fix was to force the UdpateAnchors, after updating the text of the labels, all in one frame. However, I'm not able to determine at the moment when every widget has finished to resize and everything, so I' m just waiting for a fixed amount of time in a frame before moving on (which is veeeeery bad). I hope I had explained myself :) Thanks

malo88

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UILabel bouncing when text updated
« Reply #3 on: May 19, 2017, 11:08:07 AM »
Unfortunately I'm not able to use UITable because they are not anchoring correctly to my main UI... Any other suggestion, please? :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 316
  • -Receive: 1149
  • Posts: 22,027
  • Toronto, Canada
    • View Profile
Re: UILabel bouncing when text updated
« Reply #4 on: May 25, 2017, 06:21:52 AM »
Sounds complicated. If you know what order they should go on, can't you just call UpdateAnchors in the same order, forcing them to be updated in one frame as expected? Technically NGUI is supposed to already do this though... Also note NGUITools.ImmediatelyCreateDrawCalls -- this function forces everything to be done in one go. Useful if you don't want to wait.

malo88

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UILabel bouncing when text updated
« Reply #5 on: May 25, 2017, 06:24:43 AM »
Yep, I did that :) At the moment seems the only solution and it seems also to does not affect framerate, since it'd done only on a GUI, not in game.
So, I'll go with that.
Many thanks