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.

Tip

We 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 border and inline layouts 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

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.