Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Layout

The position and size of a view is determined by its layout properties. Vizia uses a custom layout system called morphorm which can achieve similar results to flexbox.

The following sections details the functioning of the layout system:

Units

Many of the layout properties used in vizia use the Units type to specify their value. The Units type has four variants:

  • Pixels
  • Percentage
  • Stretch
  • Auto

Not all variants may have an effect on a particular property. For example, the padding properties do not use the stretch or auto variants.

Pixels

The pixels variant allows space and size to be specified with a fixed number of logical pixels. The physical space or size is determined by the window scale factor:

physical_pixels = logical_pixels * scale_factor

Percentage

The percentage variant allows space and size to be specified as a fraction of the parent size:

computed_value = percentage_value * parent_size / 100.0

The dimension is consistent, so specifying the left space as a percentage will use the parent width to calculate the desired space.

Stretch

The stretch variant allows space and size within a stack to be specified as a ratio of the remaining free space of the parent after subtracting any fixed-size space and size.

This is best understood with an example. For two views in a horizontal stack, the first with a width of stretch factor 1.0 and the second with a width of stretch factor 2.0, the first will occupy 1/3 of the horizontal free space and the second will occupy 2/3 of the horizontal free space.

Auto

The auto variant is typically the default value for a layout property and has no effect. The exception to this is with the size and size constraint properties, where an auto value represents the total size of the children of a view. So for example, setting the width to auto will cause the view to ‘hug’ its children in the horizontal direction.

Layout Properties

This section provides a list of the currently supported style properties in vizia.

PropertyTypeInitial ValueInheritedAnimatable
layout-typeLayoutTypecolumnNoNo
position-typePositionTyperelativeNoNo
alignmentAlignmentstretchNoNo
directionDirectionleft-to-rightNoNo
wrapLayoutWrapno-wrapNoNo
grid-columnsVec<Units>-NoNo
grid-rowsVec<Units>-NoNo
column-startusize1NoNo
column-spanusize1NoNo
row-startusize1NoNo
row-spanusize1NoNo
spaceshorthand-NoYes
leftUnitsautoNoYes
rightUnitsautoNoYes
topUnitsautoNoYes
bottomUnitsautoNoYes
sizeshorthand-NoYes
widthUnitsautoNoYes
heightUnitsautoNoYes
min-sizeshorthand-NoYes
min-widthUnitsautoNoYes
min-heightUnitsautoNoYes
max-sizeshorthand-NoYes
max-widthUnitsautoNoYes
max-heightUnitsautoNoYes
paddingshorthand-NoYes
padding-leftUnits0pxNoYes
padding-rightUnits0pxNoYes
padding-topUnits0pxNoYes
padding-bottomUnits0pxNoYes
gapshorthand-NoYes
horizontal-gapUnits0pxNoYes
vertical-gapUnits0pxNoYes
min-gapshorthand-NoYes
min-horizontal-gapUnitsautoNoYes
min-vertical-gapUnitsautoNoYes
max-gapshorthand-NoYes
max-horizontal-gapUnitsautoNoYes
max-vertical-gapUnitsautoNoYes