Search Unity

Resolved Layout Element max width/height

Discussion in 'UGUI & TextMesh Pro' started by David_GoRu, Aug 25, 2022.

  1. David_GoRu

    David_GoRu

    Joined:
    Jul 18, 2014
    Posts:
    5
    Hello!

    First of all, thank you very much for this opportunity.

    My question: why Layout Elements don't have a max width/height option? Seems like something that has been discussed forever (https://forum.unity.com/threads/limit-max-width-of-layout-component.316625/), and currently the only way to solve it seems to be using some code, instead of relying fully on the Layout Element. Are there any plans on implementing it?

    Thank you!
     
  2. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    I have managed to simulate max size without code by adding extra "filler" objects with Layout Elements, and carefully setting up layout groups, layout elements and whatnot, depending on the situation, but it can be time consuming and a bit messy to get it right, a max size option would be great. I suspect it may require more changes than it seems to the layout system, though.

    As a simple example, say you want a single object with max height = 500 centered vertically on a screen with height 1000. You can do something like this:
    That way the fillers will take at least 500 (or more if they can), leaving the object with 500 maximum. Other kind of setups may need a different and more complex approach.
     
  3. David_GoRu

    David_GoRu

    Joined:
    Jul 18, 2014
    Posts:
    5
    Thank you for sharing that! Never thought of it. It's not the best way, but definitely a good workaround. Although I still hope they can add an easier option, following the "min height/width" option, for consistency. I'll add that method to my list, though!
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Sorry for the delay missed this in all the other questions!

    Although a interesting idea not something that ever made it to the top of our development list. With current focus on UI Toolkit smaller feature requests like this will likely not be done in the foreseeable future. What Trisibo suggested sounds like a good workaround although not ideal from simplicity standpoint.