Author Topic: CalculateAbsoluteWidgetBounds issue with label resizing freely  (Read 3352 times)

freefall

  • Guest
CalculateAbsoluteWidgetBounds issue with label resizing freely
« on: October 05, 2013, 06:05:00 AM »
This issue has started since I upgraded to 3.0 and the new options for label overflow.

Basically want I've been doing is changing a label's text, calculating the new bounds, and based on those bounds create a speech bubble around the custom text.

However, when the label is set to 'Resize Freely', it does not seem to calculate the bounds based on the new text, but instead still calculates it based on the previous size. So for instance if my original label text is "new label", and I change it to "much longer label text", invoking CalculateAbsoluteWidgetBounds will only yield the old bounds.

I tried changing the overflow method back and forth between resizing freely and others as to force it to change the bounds accordingly, but it does not seem to work.

It gets more confusing because if I change the text, and then change the overflow manually through the UI, it seems to adjust the bounds correctly. However when I change the overflow method through the code, it seems to revert back to the original bounds.

Any help would be appreciated!

Other than that I have to say I'm really digging the new update

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: CalculateAbsoluteWidgetBounds issue with label resizing freely
« Reply #1 on: October 05, 2013, 11:12:03 PM »
Why are you doing it manually? o_O

Try this...

1. Create a label.
2. Create a sprite beside it, change it to be of type sliced sprite.
3. Add a UIAnchor and a UIStretch to the sliced sprite, set both to point to the label as your container.
4. Give UIStretch some padding to make it envelop your label correctly.
5. Type some text in your label and watch the sliced sprite adjust accordingly.

freefall

  • Guest
Re: CalculateAbsoluteWidgetBounds issue with label resizing freely
« Reply #2 on: October 06, 2013, 07:05:44 AM »
Thanks for your reply! That does sound a lot easier than what I'm doing, but there's one other factor that stops me from implementing your solution. There's not just one sliced sprite behind the label, there's actually three: one in the middle that isn't a sliced sprite but stays in the same proportion, and one on the right and left that expand based on the label size



How could I go about achieving this with your proposed solution? Also, am I able to move the whole speech panel (since it's parented to a moving unit) while it has a UIAnchor attached to it?

Thanks for your help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: CalculateAbsoluteWidgetBounds issue with label resizing freely
« Reply #3 on: October 06, 2013, 10:33:12 PM »
You need to merge those images into two. First is a circle. Just a circle. You set it up so that it's sliced down the middle, so that when you adjust its dimensions as a sliced sprite, it will be a box with rounded edges.

Second image is the notch on the bottom. Set it up so that it's on top of your sliced sprite, but below your label's text. Set it up so that it's anchored to the bottom of the label.

freefall

  • Guest
Re: CalculateAbsoluteWidgetBounds issue with label resizing freely
« Reply #4 on: October 07, 2013, 01:40:22 PM »
You need to merge those images into two. First is a circle. Just a circle. You set it up so that it's sliced down the middle, so that when you adjust its dimensions as a sliced sprite, it will be a box with rounded edges.

Second image is the notch on the bottom. Set it up so that it's on top of your sliced sprite, but below your label's text. Set it up so that it's anchored to the bottom of the label.

Thanks! Getting the sliced sprite working with a circle was definitely a million times easier than the approach I was going for.

I'm still experiencing a bit of a problem though. Basically I have this speech bubble sitting in a 3d environment. So I instantiate the template panel I have, change the text, and then enable onlyRunOnce on the UIStretch. I'm basically left with the correctly sized speech bubble at the origin without a UIStretch attached. I went about it this way because otherwise I was sure the UIStretch would start deforming it.

The problem comes that when I try to move the panel, through parenting, UIAnchor or other ways, the stretching still makes the label wider the further it goes away from the origin. If I do it manually in the game it doesn't happen, but if I do it through code right after calling onlyRunOnce = false it still gets more margin the further away from the origin.

I'm probably using a pretty retarded way to go about this again, so I'd love to hear if there's a better way.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: CalculateAbsoluteWidgetBounds issue with label resizing freely
« Reply #5 on: October 08, 2013, 01:51:26 AM »
Wider the further it goes from the origin? I'd check the hierarchy. UIAnchor works on sibling objects, and so does UIStretch. It won't work when targeting children or parents. This limitation was removed in the latest Pro version, but I am guessing you don't have that.