Author Topic: UILabel won't resize freely when anchored  (Read 8355 times)

ceefurn

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
    • twitter profile
UILabel won't resize freely when anchored
« on: August 20, 2014, 01:05:55 PM »
I'm trying to make a simple currency container from a sliced sprite that grows and shrinks horizontally to fit a UILabel. I set the anchor on the UILabel to unified and made the sprite container the target. Then when i go to set the Overflow to ResizeFreely it doesn't let me select it. It automatically just bounces back to ShrinkContent. Any ideas what's happening here?

Attached is what the widget looks like. I want the box to expand to fit if the player gets more than three characters' worth of coins.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel won't resize freely when anchored
« Reply #1 on: August 20, 2014, 05:53:03 PM »
Resize Freely won't work if you anchor something. ResizeFreely would adjust the widget's dimensions, and so would anchoring it. The two would conflict.

Consider using the EnvelopContent script. It can be used to resize some widget to envelop a group of widgets. You can anchor things to this widget as you see fit.

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
Re: UILabel won't resize freely when anchored
« Reply #2 on: August 29, 2014, 09:15:45 AM »
I'm now adopting the new anchoring system and am encountering this issue. I want to anchor a label with a background to the screen, and I want the label (and the background) to resize freely.

What hierarchy (label, background, anchoring and envelopConent) would you suggest using to accomplish this?
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel won't resize freely when anchored
« Reply #3 on: August 30, 2014, 09:12:37 AM »
Advanced anchor the label, anchoring top and left corner, leaving right and bottom unanchored. Change the label's pivot to top-left as well. Change the label to resize freely. Set the background widget (which should be the label's child ideally) to be fully Unified-anchored to the label (left to left, right to right, etc), so that it resizes with the label.

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
Re: UILabel won't resize freely when anchored
« Reply #4 on: August 30, 2014, 02:24:59 PM »
That works for my current situation - a single resize freely label and a background. Thanks.

What are the circumstances that require the EnvelopContent script you referred to here to be used?

In particular, I have a complex combo of widgets some of which can dynamically change size during runtime (aka labels that can resize freely, with a background that is anchored to the label). The label itself is not the top gameobject in the combo. I want to anchor this combo to a place on the screen.
« Last Edit: August 30, 2014, 04:01:33 PM by Maxii »
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel won't resize freely when anchored
« Reply #5 on: August 31, 2014, 02:52:17 PM »
EnvelopContent can resize a widget to use the bounds of not just one widget, but all the widgets within the chosen hierarchy. Most common use -- resizing a background to envelop the content, such as in a custom tooltip containing multiple elements.