Builder

public struct Builder

The builder is the primary surface area you interact with when using a LayoutWriter.

It provides you the ability to manage the sizing and measurement of the final layout, alongside methods to add and manage the children of the layout.

Managing Sizing

  • How the size of the layout should be calculated. Defaults to .unionOfChildren, which means the size will be big enough to contain the frames of all contained children.

    Declaration

    Swift

    public var sizing: Sizing

Managing Children

  • The children of the custom layout, which specifies the child element and its frame.

    Note

    You rarely need to access this property directly. Instead, add children via the various provided add(...) methods. However, if you’re map-ing over an array or other collection of content, using this property directly is useful.

    Declaration

    Swift

    public var children: [Child]
  • Adds a new child element to the layout with the provided frame and optional key.

    Declaration

    Swift

    public mutating func add(
        with frame: CGRect,
        key: AnyHashable? = nil,
        child: Element
    )
  • Adds a new child element to the layout.

    Declaration

    Swift

    public mutating func add(_ child: Child)
  • Enumerates each of the children, allowing you to modify them in place, eg to align them all along a common alignment axis or to set a uniform size.

    Declaration

    Swift

    public mutating func modifyEach(using change: (inout Child) -> Void)