Component Palette Icon:

On this page ...


The flex container provides an efficient way to lay out, align, and distribute space among components in the container particularly when their size is unknown or dynamic. The Flex Container can alter a component's width and height to best fill the available space to accommodate all types of devices and screen sizes. It expands components to fill available free space, or shrinks them to prevent overflow.

The container works off of two axes: main axis and cross axis. Components will fill out the container along the main axis. Additional alignment and justification of the components are determined by the alignItemsalignContent, and justify properties.

The flex container is based off the CSS flexbox


Properties

Most Properties have binding options. For more information on Bindings, see Types of Bindings in Perspective.
This section only documents the Props Category of properties. The other Categories are described on the Perspective Component Properties page.

NameDescriptionProperty Type
directionDirection of the child layout. Options are row, row-reverse, column, column-reverse.value: string 
wrapWhether the container should allow children to wrap to the next line if space has run out. Options are nowrap, wrap, wrap-reverse.value: string 
justifyAdjusts placement of children along the main axis when there is extra space, which may be used to fill areas before, after, or in-between: flex-start, flex-end, center, space-between, space-around, space-evenly.value: string 
alignItemsAdjusts placement of children along the cross axis when there is extra space: flex-start, flex-end, center, baseline, stretch.value: string 
alignContentAdjusts alignment of wrapped content when there is free space in the cross axis: flex-start, flex-end, center, space-between, space-around, stretch.value: string 
styleUse Style and Classes to customize the visual style of the component. The Style menu contains all the tools for modifying text, background, margins, borders, and more. You can also specify a style class.object


Child Component Position Properties

When a component is placed inside of a flex container, it will inherit the position properties listed below.

PropertyDescriptionData Type
growAbility to grow in the direction dimension as needed, relative to siblings. If space is available and grow is not zero, it may stretch, depending on sibling rules. This value is relative to other components, meaning that two components with the same grow value will grow at the same rate.value: numeric
shrinkAbility to shrink in direction dimension as needed, relative to siblings. If space is available and grow is not zero, it may stretch, depending on sibling rules. This value is relative to other components, meaning that two components with the same shrink value will shrink at the same rate.value: numeric
basisSpace filled by component by default, before grow, shrink and sibling considerations are evaluated. This is the component's base width when the direction property is set to row, and it is the component's base height when the direction property is set to column.value: numeric
displayDetermines if the component will be displayed in the container or not. Components that are not displayed won't just be invisible, but will actually be removed from the Flex container, readjusting all other components to fit.value: boolean


Growing and Shrinking

The Flex container's grow and shrink properties allow a great deal of control over how different components expand and shrink. To demonstrate, here are three components nested inside a Flex container, with a direction of row:


All three components have the same basis, so at this session width, they all have the same size. However, the blue component has a much larger grow value than the other two components. So, when we increase the length of the Flex container along its direction property:


The blue component does most of the stretching. Specifically, since the sum of all grow properties is 1 + 1 + 5 = 7, and the blue component has a grow property of 5, for every 7 pixels the Flex container grows, the blue component will grow by 5 pixels. Now let's try shrinking the container, noting that the red component has a shrink value of 5:

As you can see, a larger shrink value will make the container shrink more. For every 7 pixels the Flex container loses, the red component will lose 5 pixels.

Static Widths

Now let's try the same example again, but with some different grow and shrink values:


We've given the red and green components identical values, so they should stretch and shrink at the same rate. Meanwhile, the blue component's grow and shrink values are both 0, so when we make the Flex container wider, it stays the same size:

Even Scaling

Now let's say we start off with a blue component twice the basis of the others:


In order to maintain this ratio as the width of the container increases, it must have a grow value twice that of the others:


User Interface

When a Flex container is deep selected, there is a Graphical User Interface (GUI) at the top of the Perspective Property Editor that enables you to set the container's properties. Functionality is similar to that of the properties in the Props Tree, but you may find the visual interface easier or quicker to use.

Direction

This sets the direction for the child layout. Options are Row or Column. When the Reverse icon is selected, the contents of this container are displayed in reverse order.

Direction: Row

The following table shows the icons and properties they represent when Direction: Row is selected. The icon that's displayed if Reverse order is selected is also shown.

Note: Left/right/top/bottom notes in the descriptions refer to non-reversed directions.
The phrase "when there is extra space" means when no components have are stretching to fill the space. That is, when no components have "grow" greater than 0.


Items
Row IconRow Reversed IconProperty

Description

Flex StartChild items are placed along the start (top) of the container when there is extra space.

CenterChild items are placed along the center of the container when there is extra space.

Flex EndChild items are placed along the end (bottom) of the container when there is extra space.

StretchChild items are stretched from top to bottom of the container.

BaselineChild items are placed so the baseline of the text matches for all of them when there is extra space.
Justify
Row Icon
Row Reversed IconPropertyDescription

Flex startAdjusts placement of children to the start (left) of the container when there is extra space. If reversed, children are placed along the right.

CenterAdjusts placement of children along the center of the container when there is extra space.

Flex EndAdjusts placement of children along the end (right) of the container when there is extra space. If reversed, children are placed along the left.

Space Between

Adjusts placement of children with space in between them reaching to the edges of the container when there is extra space.

Space Around

Adjusts placement of children with even spacing in between them with some space along the edges when there is extra space.


Space EvenlyAdjusts placement of children with even spacing in between them and the edges of the container when there is extra space.
Children
IconPropertyDescription
N/ADon't WrapIf there are more components than the width allows, shrink them.
N/AWrapIf there are more components than the width allows, wrap onto the next line.

Reverse WrapToggle to reverse the direction of wrap from top-down to bottom-up
Content (Only applicable when Children:Wrap is selected.)
Row Icon
Row Reversed IconPropertyDescription

Flex startAdjusts placement of wrapped content to the start (top) of the container when there is free space.

CenterAdjusts placement of wrapped content to the middle of the container when there is free space.

Flex EndAdjusts placement of wrapped content to the end (bottom) of the container when there is free space.

Space BetweenAdjusts placement of wrapped content evenly with space in between each wrapped line, reaching to the edges (top and bottom) of the container when there is extra space.

Space AroundAdjusts placement of wrapped content evenly with space in between each wrapped line and the edges (top and bottom) of the container when there is extra space.

StretchAdjusts placement of wrapped content evenly with space in between each wrapped line and after the last line (bottom) of the container when there is extra space.

Direction: Column

The following table shows the icons and properties they represent when Direction: Column is selected. The icon that's displayed if Reverse order is selected is also shown.


Items
Column IconColumn Reversed IconPropertyDescription

Flex startChild items are placed along the start (left) of the container when there is extra space.

CenterChild items are placed along the center of the container when there is extra space.

Flex EndChild items are placed along the end (right) of the container when there is extra space.

StretchChild items are stretched from left to right of the container.

Baseline

Child items are placed so the baseline of the text matches for all of them when there is extra space.

Justify
Column Icon
Column Reversed IconPropertyDescription

Flex startAdjusts placement of children to the start (top) of the container when there is extra space. If reversed, children are placed along the bottom.

CenterAdjusts placement of children along the center of the container when there is extra space.

Flex EndAdjusts placement of children along the end (bottom) of the container when there is extra space. If reversed, children are placed along the top.

Space BetweenAdjusts placement of children with space in between them reaching to the edges of the container when there is extra space.

Space AroundAdjusts placement of children with even spacing in between them with some space along the edges when there is extra space.

Space EvenlyAdjusts placement of children with even spacing in between them and the edges of the container when there is extra space.
Children
IconDescription
N/ADon't WrapIf there are more components than the width allows, shrink them.
N/AWrapIf there are more components than the width allows, wrap onto the next line.

Reverse

Toggle to reverse the direction of wrap from top-down to bottom-up

Content (Only applicable when Children:Wrap is selected.)
Column Icon
Column Reversed IconPropertyDescription

Flex startAdjusts placement of wrapped content to the start (left) of the container when there is free space.

CenterAdjusts placement of wrapped content to the middle of the container when there is free space.

Flex EndAdjusts placement of wrapped content to the end (bottom) of the container when there is free space.

Space BetweenAdjusts placement of wrapped content evenly with space in between each wrapped line, reaching to the edges (left and right) of the container when there is extra space.

Space AroundAdjusts placement of wrapped content evenly with space in between each wrapped line and the edges (left and right) of the container when there is extra space.

StretchAdjusts placement of wrapped content evenly with space in between each wrapped line and after the last line of the container when there is extra space.


Component Functions

  • Description

Returns an ArrayList, which contains references to all components inside of the container.

  • Parameters

none

  • Return

Array List - An ArrayList of components in the container. The resulting ArrayList can be iterated over via a for-loop.


Example

In the following example, we have three components inside a Flex container: Button, Thermometer, and LED Display. The position properties for the Button and LED Display are set so that their size will not change if the Flex container is resized. However, the Thermometer will shrink or grow depending on the Flex container size.

The following properties are set for the Flex Container:

Property

Value

props.directionrow
props.wrapnowrap
props.justify

space-between

props.alignItemscenter
props.alignContentflex-start

The following properties are set for the Button component within the container:

Property

Value

props.textNext Tank
position.grow0
position.shrink0
position.basis80px

The following properties are set for the Thermometer component within the container:

Property

Value

props.directionrow
position.grow1
position.shrink1
position.basis50%

The following properties are set for the LED Display component within the container:

Property

Value

position.grow0
position.shrink0
position.basis80px


  • No labels