Layouts
Each Alfred UI begins with a layout which defines how components are laid out in a view.
Layouts are automatically responsive, and designed to be stacked and broken down into small, manageable parts, each which can live within their own JSON.
A layout is assigned to the layout key of a view component. The chosen layout will arrange and position components added to the view's components array, taking into account any constraints added to each component.
TipWe recommend building a UI by breaking it down into each visual group of components, and picking the layout most suitable to that group. Many UIs could be built from stacking the
borderandinlinelayouts alone.
Each layout has its merits, and once you've mastered which layouts to use throughout your UI, creating beautiful UIs will become second nature.
Layout Types
Stack Layout
The simplest layout, which fills each component to the maximum space available
Border Layout
Components are positioned in one of five regions based on a component's region constraint
Grid Layout
Components are arranged in an equal-sized grid based on rows and cols properties
Inline Layout
A deceptively simple layout allowing components to be arranged horizontally or vertically
Form Layout
A specialised layout which organises components in pairs, for simple forms or complex configuration screens
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.
Take a look in the ui.json of any Alfred UI to see how layouts have been applied.
Constraints
Layout constraints facilitate both essential layout hinting, and further finite control of component layout within the allotted space.
Each individual layout will define which constraints are required, and the constraints documents the shared constraints and how to apply them.
Resizing Behaviour
A significant benefit of Alfred UI's layouts is that your user interfaces will be automatically sized and laid out based on their content.
Each view will calculate its desired size based on the components added to it, including any additional constraints such as padding or spacing. Calculated from the smallest components, all the way up the hierarchy to the root view, this beautiful interaction between component sizing and layouts is what gives you a responsive layout.
Initial sizing of the window will be either set using the size property of the window, or automatic based on the layouts and component's desired sizes.
Each layout will have subtly different behaviour for resizing to achieve its layout goals, and in most cases, this will be fully predictable. Read the Resizing Behaviour heading on each layout page to understand the resizing logic.