Author Topic: Incorrect CalculatePrintedSize after UpdateNGUIText()  (Read 3952 times)

jphales

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Incorrect CalculatePrintedSize after UpdateNGUIText()
« on: June 24, 2016, 08:53:41 PM »
Hello ArenMook, everyone.

Thanks for the awesome tools!

I've read a half dozen posts related to this and most are solved simply by ensuring the UILabel's UpdateNGUIText() is called before NGUIText.CalculatePrintedSize().
I'm receiving what seems like incorrect Y bounds information even after doing the above when the text runs over into a new line -- But not always. [pic1]
When this happens, if I add a few more characters the bounds update correctly. [pic2]

Dynamic fonts, shrink content, center aligned.
Code is also simple, resizing a UISprite behind text. Nothing fancy.

Am I missing something simple? Please see the attached images.
Thanks.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Incorrect CalculatePrintedSize after UpdateNGUIText()
« Reply #1 on: June 27, 2016, 06:03:30 AM »
With shrink content it may not be clear what will end up happening. Why are you calling CalculatePrintedSize yourself anyway? That entire dialog can be set up to look the way it does by using anchors. Background anchored to the label, button anchored to either the label or the background.

jphales

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Incorrect CalculatePrintedSize after UpdateNGUIText()
« Reply #2 on: June 27, 2016, 05:16:11 PM »
Thank you so much for the response ArenMook.

The Label content changes dynamically (from a couple words, to several sentences) and must be confined to a specific screen area (we have more UI going on.) So, the label is anchored already to a 'shrink content' box area. We want the background to readjust dynamically to only the text in the label, not the entire label's anchored area.

Anything else we might use to fudge the results in our favor or is shrink content just tricky?

Thanks again!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Incorrect CalculatePrintedSize after UpdateNGUIText()
« Reply #3 on: June 28, 2016, 09:25:27 AM »
I think you should considering looking at the EnvelopContent script. It can be used to adjust one widget's size to envelop one or a group of widgets -- perfect for resizing backgrounds to cover some area.