WaterfallLayout in Feathers containers
WaterfallLayout class may be used by components that support layout, such as
ScrollContainer, to display items with multiple columns of equal width where items may have variable heights. Items are added to the layout in order, but they may be added to any of the available columns. The layout selects the column where the column's height plus the item's height will result in the smallest possible total height.
WaterfallLayout supports a number of useful options for adjusting the number of columns, the spacing between items, and the alignment of the columns.
First, let's create a
WaterfallLayout and pass it to a
There are a number of simple properties that may be used to affect positioning and sizing of items in the layout. Let's look at some of the most common.
The padding is the space around the edges of the container. Let's set the
padding property to
If needed, we may set padding on each side of the container separately. Below, we set the
10 pixels, and we set the
The gap is the space between items. Let's set the
gap property to
If needed, we can set the horizontal and vertical gaps separately. We'll set the
horizontalGap property to
4 pixels and the
verticalGap property to
We can align the columns in the layout using the
horizontalAlign property. Let's adjust the horizontal alignment so that the content will be pulled to the right:
It's possible to request a specific number of columns for the layout to display. The layout may not always be able to accomodate this value because the container may be too small, but if there is enough room for the requested number of columns, that's the number it will display. Let's tell the layout to use three columns by setting the
Now, the layout will always display three columns, even if the container can fit four or more. However, if only one or two columns can be fit into the container, the layout will display the maximum number that will fit.