Search Unity

Grid Layout ?

Discussion in 'UI Toolkit' started by mentalgear, Jul 26, 2021.

  1. mentalgear

    mentalgear

    Joined:
    Jul 19, 2019
    Posts:
    23
    I'm wondering if UI Toolkit can produce a item-grid layout in horizontal and vertical axis, similar to CSS flex items. Best responsive where the items auto adjust based on the container grid width.
     
  2. RunninglVlan

    RunninglVlan

    Joined:
    Nov 6, 2018
    Posts:
    182
  3. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    Yup; as Running|V|an pointed out, it's all based on CSS. Put this in your USS:

    Code (CSharp):
    1. flexDirection: row;
    2. flexWrap: wrap;
    Or in C#:

    Code (CSharp):
    1. scrollView.contentContainer.style.flexDirection = FlexDirection.Row;
    2. scrollView.contentContainer.style.flexWrap = Wrap.Wrap;
    I've only done it with items that are roughly the same size. I don't know exactly how it handles wrapping with nonuniform elements.
     
  4. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    356
  5. mentalgear

    mentalgear

    Joined:
    Jul 19, 2019
    Posts:
    23
    Thanks for your replies, would something like this be possible in UI Toolkit?
    Any idea on how to best set it up?
    http://ui-example.webflow.io