Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to treat TMP text width as min-size (not preferred)

Discussion in 'UGUI & TextMesh Pro' started by Flavelius, Jan 31, 2023.

  1. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    943
    Hi,
    I have two tmp text elements inside a Horizontal layout group (only Control Child size (w/h) enabled).
    Both fight for the available space when their combined length exceeds the full width and both then shrink to fit by default.
    What i need is one to not shrink to fit (use its size as min-width) while the other is allowed to (treated like preferred width).
    How can i achieve that?
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    943
    It kind-of works with this setup
    [Base Horizonal-group(Control child size (w/h) enabled)]
    - [TMP-Text that's allowed to shrink]
    - [Horizontal-Layout-group (Control child size off for width, enabled for height)]
    - - [TMP-Text with Content Size Fitter (horizontal set to preferred)]
    This gives the correct result at edit-time, but sometimes doesn't correctly fit at runtime. Most of the time calling LayoutRebuilder ForceRebuildLayout or MarkForRebuld multiple times after adjusting the text fixes it fortunately, but feels like a hack and a hackfix.
    Is there a different, normal way?