How to use TiledRowsLayout with Feathers UI containers
TiledRowsLayout class may be used to position items from left to right, wrapping to multiple rows. All items are positioned within tiles that have the same width and height. This layout supports a number of useful options for the spacing and alignment.
This layout is designed to be used with basic containers like
ScrollContainer, which are intended purely for visual layout and do not offer built-in capabilities for rendering data from a collection. If using a container that renders a collection of data — such as
GridView— consider using
TiledRowsListLayoutinstead because it is better optimized for data containers by offering performance improvements like layout virtualization.
var container = new LayoutGroup(); addChild(container); var child1 = new Button(); child1.text = "One"; container.addChild(child1); var child2 = new Button(); child2.text = "Two"; container.addChild(child2); var child3 = new Button(); child3.text = "Three"; container.addChild(child3);
container.layout = new TiledRowsLayout();
By default, the first child will be positioned in the top-left corner. Each additional child will be positioned to the right of the previous child — creating a horizontal row, until the total width exceeds the width of the parent container. Then, the next child will be positioned below the previous children to start a new row.
The following sections will introduce a number of properties that may be used to adjust the positioning and sizing of children in the layout.
layout.paddingTop = 10.0; layout.paddingRight = 15.0; layout.paddingBottom = 10.0; layout.paddingLeft = 15.0;
If all four padding properties should be set to the same value, call the
setPadding() method instead.
// sets top, right, bottom and left to the same value layout.setPadding(10.0);
layout.horizontalGap = 10.0; layout.verticalGap = 6.0;
If both gap properties should be set to the same value, call the
setGap() method instead.
// sets horizontal and vertical gaps to the same value layout.setGap(10.0);
The children of the container may be aligned within the container's bounds.
To align the children along the x-axis, set the
layout.horizontalAlign = CENTER;
To align the children along the y-axis, set the
layout.verticalAlign = MIDDLE;
Note: Vertical alignment may be used only when the total height of the content (including padding and gap values) is less than or equal to the height of the container. If the content is larger than its parent container, the layout will position the children starting from
0.0on the y-axis, the same as if they were top-aligned.
Rows and columns
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. Tell the layout to use three columns by setting the
layout.requestedColumnCount = 3;
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.
If the width of the container is not set, the layout will automatically calculate a width that accomodates the
requestedMaxColumnCount properties may be used to specify a range of columns allowed to be displayed, which depends on the number of children added to the container.