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

GridBag Style Layout?

Discussion in 'UGUI & TextMesh Pro' started by Slev, Sep 22, 2014.

  1. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    With the current layout schemes you aren't allowed much variation (save for doing it yourself.) I would like something akin to GridBag layouts (or even just better horizontal and vertical). Currently I have a horizontal layout where I want one element to always take up 80% of the width and the other two to take up 15% and 5% I currently see no way of doing this, save for sizing it myself. Are any of the layout tools sufficient for this? Or will we need to make do and wait?

    It would also be nice to be able to pad pieces of components away from their edges by a set amount without using one of the strict layouts.
     
    Last edited: Sep 22, 2014
  2. Agostino

    Agostino

    Joined:
    Nov 18, 2013
    Posts:
    21
    Like Java's GridBag where you have to set constraints left and right?
    What about something like Qt's nested layouts?
    A vertical layout that can contain a horizontal layout (without creating an additional panel!), and gracefully resizes by itself without specifying a ton of constraints?
     
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    Yes. You said you have a Horizontal Layout Group. Add a LayoutElement to each child and set the FlexibleWidths to 80, 15, and 5. Make sure Minimum and Preferred Widths are all 0.

    The basic anchoring functionality can be used to make a rect be a set distance away from the edge of the parent.
     
  4. Slev

    Slev

    Joined:
    Sep 8, 2012
    Posts:
    148
    Ah, I didn't know the internal LayoutElements could override the Horizontal/Vertical layouts. Thank you.
     
  5. salmonmoose

    salmonmoose

    Joined:
    Sep 19, 2014
    Posts:
    3
    Sadly the grid-layout doesn't appear to support this functionality - the ratio fitter doesn't play nicely.

    I would like my primary layout to consist of 3 elements, a central square, and an element that fills from the bottom left, and one from the top right.

    This would provide space at the sides on landscape, and at the top in portrait - those elements could sort themselves out once everything else is in order. I can't seem to pin things to the parent and have them grow, and the grid forces element's sizes.
     
  6. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    It's inconvenient that the grid doesn't work for this, but what does seem to work is having a panel (just a rect-transform and nothing else) with a vertical layout, then panels for each row with horizontal layouts, then the elements arranged inside. This works only if you know ahead of time your number of rows/columns, though.
     
  7. salmonmoose

    salmonmoose

    Joined:
    Sep 19, 2014
    Posts:
    3
    For my case, this wouldn't work, as I want my primary layout to switch between horizontal and vertical, a grid layout would change the order nicely, but so would having layout elements working on a non-layout group.