I have a container panel to which I want to drag objects of varying size and automatically place them one after another. Horizontal Layout Group works perfectly for this, except when items don’t fit on a row. What I’d like to happen is start a new row instead of overflow. Any way to do this currently? Or do I just have to code it myself?
I am assuming a Grid Layout is not working because of the varying height?
Ugui does not include a flowlayout at this time, I don’t think grid can do this without tweaking scripts.
A workaround might be to use grid layout, but instead of placing your cells directly under it, use a wrapper game object that provides filler so you can make your objects varying height.
I want to have items of varying width (FlowLayout, yeah), so GridLayout doesn’t work.
You could wrap horizontal layouts with X items in a a vertical layout, then create a new horizontal layout every X items and fill it. Thus each Horizontal layout could have it’s own height. But that means you have a certain number of items per horizontal layout. Not sure if that helps.
It’s probably possible to (instead of using a fixed number per row) check if the next item would be invisble (cause of a mask or something) and if so, to add it to the next row.
Multiple horizontal layouts would require custom logic to calculate whether new items fits or not anyway, so it’s basically the same as creating a custom solution, which it seems I have to do.
Also, like I said, it’s about varying width. I don’t know why everyone thought the opposite (granted, I said varying size instead of width), but in this case the height is fixed.
Ha. You’re right. That’s a weird assumption. Regardless, if you do make a custom solution, please share it
While I think the HorizontalLayoutGroup is nice, it does a few things that are really weird and not what I’d want it to. Frex if you put in a bunch of panels and tell it not to expand to width/height those things are 10x10 only, probably because that’s the size of the image unsliced. That’s a bit inconvenient.
The workaround I mentioned will work for varying widths too, but it will have the caveat of having the columns for each row lined up. If if you don’t want the columns to line up then you have to roll your own. It’s relatively easy to modify the source code for horizontal layout to add line breaks where you need them. Find the source in the mono develop browser. F12 on the text for the class name.