Custom Layout

You can create your own layouts by implementing Flexalon.Layout. To make this easier, we provide the FlexalonLayoutBase MonoBehaviour that you can extend. This component will handle child management and working correctly in edit mode.

To implement a layout, you need to override two methods: Measure and Arrange.

HINT: An example CustomLayout script can be found in the Samples/Scripts directory.


A FlexalonNode is automatically created for each gameObject managed by Flexalon. A node holds layout state which is shared between different components and stores the layout results. In implementing Measure and Arrange, you will need to become familiar with this class.

Layout Space

In implementing your layout's Measure and Arrange methods, you are measuring and arranging your children in Layout Space. This is different from both Unity world space and local space.

In Layout Space, you can assume that:

1. Your layout node's center is at (0, 0, 0).

2. Each child pivots at the center of its size.

3. All sizes are axis aligned.

4. You can also ignore margin and padding, as they are handled exernally.

Essentially, your task is to measure and arrange a set of simple boxes.


Bounds Measure(FlexalonNode node, Vector3 size)

node The node representing the gameObject to be measured.
size The size of the node, determined by the Flexalon Object Component. You need to determine the size of any axis set to SizeType.Layout.
Return Value The bounding volume for this layout.

In the Measure step, Flexalon needs you to determine two things: the fill size for children using SizeType.Fill and the total size of the layout. Access node.Children and set each child's fill size by calling child.SetFillSize. You can access each child's size by calling child.GetMeasureSize its and size type by calling child.GetSizeType.

Measure may be called multiple times with different sizes during a single layout update. This is because children using SizeType.Fill, may change their size based on the layout or adapter attached to them. For example, consider a text object with width set to SizeType.Fill and height set to SizeType.Component. Once the text gets a fill size, it may choose to wrap its text, which will change its height, which may change how you measure your layout.


void Arrange(FlexalonNode node, Vector3 layoutSize)

node The node representing the gameObject whose children are to be arranged.
layoutSize The size of this layout computed in the Measure step, possibly adjusted by an adapter.

In the Arrange step, Flexalon is asking you to position and rotate each child. Access node.Children and set each child's position with child.SetPositionResult and rotation with child.SetRotationResult. You can access each child's size by calling child.GetArrangeSize. Arrange will only be called once in a layout update.

© 2023 Virtual Maker Corporation Privacy