Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Layout element max size

Discussion in 'UGUI & TextMesh Pro' started by Johannski, Dec 8, 2014.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    815
    Hey everybody,

    I've done quite a lot of stuff with uGUI and now I found a limitation, I can't really solve with the GUI elements, but which is pretty basic and should work out of the box. I would like to see a max size in the layout element. Why do I need this. I would like to make a collapsing menu element, which shows options once it's been clicked. Here a small example of what I want:


    This works by disabling the objects in the menu, and setting a preferred width of the wrapper, which has the size of the button. This is not very clean, and I can't animate it properly. So that's why I think the feature would be necessary.

    What do you think? Did I miss anything, with which I could solve that problem?
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    I'm not sure exactly what you mean, but LayoutElement has no max size property because it's equivalent to the preferred size as long as flexible size is 0.
     
    MrMatthias and mahdi_jeddi like this.
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    815
    Sorry for the late response, I somehow missed your answer. Not quite, I set the preferred Height to 60 and the flexible Height to 0, but when my content inside exeeds the 60 pixels, the parent object grows to the size of the content. The parent object also contains a vertical layout group, but that shouldn't be the problem right?!

    €dit: This is the setup for the gif in my first post, when I enable the content, the parent object increases in size to the child objects, even though the preferred height is 60.
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    Not as long as you disable Child Force Expand on the VerticalLayoutGroup.
     
  5. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    815
    Thanks for still caring, and sorry for my late reply. I found, that my problem was, that I set a min height property. After removing all min heights, the panel still needed space because of the text fields I think. My solution now is, that I put the button, from which the dropdown menu should come from, in front of everything else, and let it ignore the layout. That way I can hide the other content behind it. Not too elegant, but works for me right now. If somebody has a better idea on how to work around this problem, please post it :)

    Here is my current result (Which I can tweak with the animator):
     
    Last edited: Jan 6, 2015
  6. FelipeDias

    FelipeDias

    Joined:
    Nov 25, 2012
    Posts:
    2
    How did you made this tweek animation with ugui?
     
  7. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    815
    Yep this is all uGUI. You have to use an Animator, in which you can add animations. Those animations then can animate properties of uGUI. :)
     
  8. UIGuy

    UIGuy

    Joined:
    Jan 22, 2015
    Posts:
    7
    That is the 2nd time I've seen you tell people this. It's simply not true. When you set a Preferred Width and Flexible Width to zero, the Layout Group DOES NOT LIMIT THE SIZE to that preferred width.
     
    _TheFuture_ likes this.
  9. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    Yes it does, as long as you disable Child Force Expand on the layout group.

    If you're seeing otherwise, please file a bug and post the case number here so we can fix it. Thanks.
     
    DevDeveloperDev and arkano22 like this.
  10. mgstauff

    mgstauff

    Joined:
    Sep 6, 2017
    Posts:
    59
    I saw another thread about this issue that I can't find right now, in which I believe runevision said it ends up not being correct that setting Flexible [Width|Height] to 0 yields a max size of the matching Preferred value. And even if it did, wouldn't that mean that the preferred setting becomes the max, and we wouldn't be able to have a preferred setting that's different than a max? e.g. I'd like a preferred width of 200, but have it max out at 400.
     
    WilliamLeonard likes this.
  11. ThorBrigsted

    ThorBrigsted

    Joined:
    Dec 23, 2016
    Posts:
    2
    It's not limiting the size for me either in 2018.2. Has a bug been filed yet?
     
  12. Arshak_A

    Arshak_A

    Joined:
    Jun 22, 2018
    Posts:
    1