flex Layout
The most flexible and complex layout available, allowing components to be laid out in a flexible grid, with components spanning multiple rows or columns. It is a powerful layout for complex interface areas.
{
"type": "view",
"layout": "flex",
"spacing": 4,
"rows": 3,
"cols": 3,
"components": [
{
"constraints": { "grid": { "col": 0, "row": 0, "colspan": 2 } },
"type": "button",
"text": "First"
},
{
"constraints": { "grid": { "col": 2, "row": 0, "colspan": 1 } },
"type": "button",
"text": "Second"
},
{
"constraints": { "grid": { "col": 0, "row": 1, "colspan": 1 } },
"type": "button",
"text": "Third"
},
{
"constraints": { "grid": { "col": 1, "row": 1, "colspan": 2 } },
"type": "button",
"text": "Fourth"
}
]
}
Components are explicitly positioned and sized within the constraints of the grid.
NoteWhile the
flexlayout offers ultimate flexibility, we recommend approaching user interface design in a modular manner: Break your UI down into simpler layouts such as theborderandinlineand composite these views into your final UI.
Properties
- padding
- INTEGER
- Default:
0, Range:0-64
Inset the content around the perimeter of the view by the padding amount.
Constraints
Constraints set on each component added to the view:
- grid
- OBJECT
- Required for
flexlayout
Each component can use the shared constraints to refine their position within the layout.
Resizing Behaviour
The flex layout resizes rows and columns proportionally based on the components added to it.
You can control how much weighting each row or column has with the colweight and rowweight grid constraints. By default these weightings are set to 0.0, so adding a weight to a single column or row will make it take up the maximum available remaining space. You can balance weights between multiple rows and columns to get interesting or desirable proportional layouts as the window resizes.
If you set a weight on a row or column with a rowspan or colspan larger than 1, this weighting is divided by the span amount. The algorithm will use the maximum set weightings for components sharing the same row or column.
Examples
The icon for the Try Alfred UI workflow
NoteWhile it is recommended to be explicit, the default
typeof a component isviewand itslayoutproperty isstack. Here we took advantage of that to have components as simple as{ "background": "White" }, which translates to a basicstacklayout with a colour. For theflexviews we omittypebut definelayout.
{
"background": "Black",
"components": [
{
"layout": "flex",
"cols": 3,
"rows": 3,
"padding": 10,
"spacing": 10,
"components": [
{
"constraints": { "grid": { "colspan": 2, "rowspan": 2 } },
"background": "systemRedColor"
},
{
"constraints": { "grid": { "col": 2 } },
"background": "systemYellowColor"
},
{
"constraints": { "grid": { "col": 2, "row": 1 } },
"layout": "flex",
"cols": 2,
"rows": 1,
"spacing": 10,
"components": [
{ "background": "White" },
{
"constraints": { "grid": { "col": 1 } },
"background": "White"
}
]
},
{
"constraints": { "grid": { "row": 2, "colspan": 2 } },
"components": [
{
"layout": "flex",
"cols": 2,
"rows": 2,
"spacing": 10,
"components": [
{
"constraints": { "grid": { "col": 1 } },
"background": "White"
},
{
"constraints": { "grid": { "row": 1 } },
"background": "White"
},
{
"constraints": { "grid": { "col": 1, "row": 1 } },
"layout": "flex",
"cols": 1,
"rows": 2,
"components": [
{ "background": "White" }
]
}
]
}
]
},
{
"constraints": { "grid": { "col": 2, "row": 2 } },
"background": "systemBlueColor"
}
]
}
]
}