Search Unity

Layout Group - horizontal layout new line

Discussion in 'UGUI & TextMesh Pro' started by Modernllama, Feb 20, 2019.

  1. Modernllama

    Modernllama

    Joined:
    Nov 30, 2012
    Posts:
    19
    Hi,

    I have quite a simple use case which is basically just trying to show items of the same height but with different widths in sequence. These items would be created dynamically.

    I seem to notice a grid layout won't work as it keeps elements at a fixed width and I do want the items to wrap so if there's more items then can fit the width of the screen it goes to the second row.

    Is there a simple way around it?

    Thanks,
     
    Ex6tra likes this.
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    As far as I know there is no way out of the box.
    what you can do is having a vertical layout group where you spawn a horizontal layout group inside.
    A custom script checks if the current Horizontal Layout Group has space for a certain item. If not, it creates another horizontal layout group and sets it as current.
     
    awsapps likes this.
  3. awsapps

    awsapps

    Joined:
    Jun 15, 2021
    Posts:
    74
    It's a relative fair UI component no? similar to Flex box for css...