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.

FlexalonNode

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.

Measure

Bounds Measure(FlexalonNode node, Vector3 size, Vector3 min, Vector3 max)

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.
min The minimum size of the node, determined by the Flexalon Object Component. Ensure the returned bounds fit in min/max.
max The maximum size of the node, determined by the Flexalon Object Component. Ensure the returned bounds fit in min/max.
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/shrink size by calling child.SetShrinkFillSize. You can access each child's size by calling child.GetMeasureSize and 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.

Arrange

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.