Layout
Flexible Grid Layout
Responsive grid sizing with flexible rows, columns, and masonry
Overview
Flexible Grid Layout sizes a grid around its available space. It supports fixed row/column strategies, minimum cell sizes, aspect ratios, and masonry layouts.
Usage
Add Flexible Grid Layout to the parent of the items.
Choose a fit strategy in the Inspector.
Set minimum cell size, spacing, and padding.
Choose whether the layout controls child width and height.
Tips
- Enable Preserve Aspect Ratio to keep cell proportions.
- Fit X and Fit Y control stretching, while Masonry allows a flow that accounts for varied item sizes.
- Avoid competing layout components on the same parent. Let Flexible Grid Layout own its children’s size and placement.
Public API
Use FlexibleGridLayout in the Evo.UI namespace.
Properties
| Name | Type | Description |
|---|---|---|
Rows | int | Requested row count. |
Columns | int | Requested column count. |
MinCellSize | Vector2 | Minimum cell dimensions. |
Spacing | Vector2 | Horizontal and vertical spacing. |
ControlChildWidth | bool | Lets the layout set child width. |
ControlChildHeight | bool | Lets the layout set child height. |
FitX | bool | Fits cells along the horizontal axis. |
FitY | bool | Fits cells along the vertical axis. |
PreserveAspectRatio | bool | Preserves the configured cell ratio. |
AspectRatio | float | Desired width-to-height ratio. |
Masonry | bool | Enables masonry layout. |
CellSize | Vector2 | Read-only calculated cell dimensions. |
CalculatedRows | int | Read-only calculated row count. |
CalculatedColumns | int | Read-only calculated column count. |
Fields
| Name | Type | Description |
|---|---|---|
fitType | FitType | Current fit strategy. |
Methods
| Name | Parameters | Description |
|---|---|---|
SetFitType() | FitType type | Changes the fit strategy and requests layout. |
Example
using UnityEngine;
using Evo.UI;
public class FlexibleGridLayoutExample : MonoBehaviour
{
[SerializeField] private FlexibleGridLayout target;
private void Start()
{
target.MinCellSize = new Vector2(160f, 100f);
target.Spacing = new Vector2(12f, 12f);
target.PreserveAspectRatio = true;
target.AspectRatio = 1.6f;
}
}