List and Flex Layouts

*Konten ini akan segera tersedia dalam bahasa pilihanmu.

The UIListLayout positions sibling GuiObjects into horizontal rows or vertical columns within their parent container. Whenever you add or remove a sibling object, the layout adjusts accordingly.

Fill Direction

The FillDirection property determines the direction in which the list layout's siblings will render.

UIListLayouts illustrating FillDirection of either horizontal or vertical.

Ordering is determined by the layout's SortOrder property which can be either ascending numeric, based on each item's LayoutOrder integer value, or alphanumeric based on the item's Name.

List layout examples illustrating numerical LayoutOrder sorting or alphanumerical Name sorting.

Alignment

The HorizontalAlignment and VerticalAlignment properties determine the respective X and Y alignment of both the list's siblings in relation to each other and the list's overall bounds within its container. For example, a horizontally-filled list with VerticalAlignment of Center centrally aligns the list's siblings with each other and centers the list vertically in its container.

List layout illustrating VerticalAlignment of Center.

Wrapping

The Wraps boolean controls whether siblings within the parent container wrap to another line when their default size exceeds the width/height of the container's bounds.

Diagram showing how Wraps affects how siblings are distributed within the parent container's bounds.

Padding

The Padding property determines the amount of empty space between each list item, set to either a scale (percentage of the container's size in the current direction) or an offset (static spacing value similar to pixel size).

Flex Layouts

Integrating flex into a UIListLayout is a powerful way to equally fill/distribute or align/stretch list items across their line, or flex specific items across a variable space.

Equal Fill or Distribution

When the list layout's fill direction is set to Horizontal, the HorizontalFlex property specifies how to distribute extra horizontal space in the parent container. Similarly, when the fill direction is set to Vertical, the VerticalFlex property specifies how to distribute extra vertical space.

UIListLayout examples showing how each HorizontalFlex option affects the size and spacing of sibling UI objects.

One practical use of HorizontalFlex is a tabbed window interface where flex fills the tab bar equally, regardless of the number of tabs. No approach is easier than flex in this case, because it automatically calculates the width of each tab without developer‑defined width settings, and it automatically adjusts if the number of tabs changes.

Item Line Alignment

The ItemLineAlignment property defines the cross‑directional alignment of siblings within a line, letting you align objects of different widths/heights or make objects of lesser width/height fill their entire line.

Examples of options for ItemLineAlignment in a horizontal fill direction.

One practical use case for ItemLineAlignment is to stretch a series of inconsistently sized tiles to fill their entire row (Stretch), making the layout more cohesive.

Tiles with varying content heights result in an uneven and staggered layout

Flexing Individual Items

While flexing an entire layout is a powerful utility, certain layouts are more suited to individual item flexing. In such layouts, some elements in the list maintain their core size while other items flex to fill variable spaces. One practical usage is a slider bar widget with uniform labels on both ends and a flexible slider bar that fills the entire width between.

Example of UIFlexItem applied to a specific GuiObject under control of a UIListLayout.

To set one specific list item as flexible, insert a UIFlexItem as a child of the flexible item, then set its FlexMode property to Fill, Grow, Shrink, or Custom.

Example hierarchy of a UIFlexItem parented to a GuiObject under control of a UIListLayout.