Masonry Layout

A Masonry Layout arranges items of different heights into columns, like a photo gallery or a news feed. Each item goes into whichever column is currently shortest, so the columns stay roughly even without leaving gaps.

Space Adventure archive with varied-height cards arranged in masonry columns.
The SpaceMasonrySample scene, in Samples/SpaceAdventure/Scenes.

Set up a gallery

  1. Add Flexalon Masonry Layout to the gallery parent and add your items as children.
  2. Add columns in the inspector. Use Fill sizing for columns that share the available width.
  3. Set the parent's width to Fixed or Fill. Set each item's width to Fill and its height to Component or Layout.
  4. Choose Column Direction, Stack Direction, and gaps. For a typical gallery, place columns to the right and stack children downward.

Options

OptionBehavior
Column AssignmentShortest assigns each child to the shortest column. Round Robin cycles through columns in order.
Column sizingLayout fits assigned content, Fill shares remaining space by weight, and Fixed uses a specified size.
Column minimum / maximumLimit each column's size. A maximum of zero means no maximum.
Column Gap / Stack GapSpace between columns and between items within each column.
Column alignmentAlign content within an individual column.
Layout alignmentAlign the complete set of columns within the parent's available space.

Changing an item's size can move the items after it into different columns. If items should always stay in the same column, use Round Robin, which places items into columns in order: first, second, third, then back to the first.

Example: a card gallery

Create three Fill columns with a Column Gap and Stack Gap of 10, and give the parent a Fixed width. Add cards whose height is set to Layout so they grow to fit their text. Short and tall cards will pack together into three even columns, and resizing the parent widens every column.

Masonry Layout API reference