ElementContent

public struct ElementContent

Represents the content of an element.

Measurement & Children

  • Measures the required size of this element’s content.

    Declaration

    Swift

    public func measure(in constraint: SizeConstraint, environment: Environment) -> CGSize

    Parameters

    constraint

    The size constraint.

    environment

    The environment to measure in.

    Return Value

    The layout size needed by this content.

  • Declaration

    Swift

    public var childCount: Int { get }

Layout storage

  • Used to construct elements that have layout and children.

    See more

    Declaration

    Swift

    public struct Builder<LayoutType> where LayoutType : Layout
  • Initializes a new ElementContent with the given layout and children.

    Declaration

    Swift

    public init<LayoutType: Layout>(
        layout: LayoutType,
        configure: (inout Builder<LayoutType>) -> Void = { _ in }
    )

    Parameters

    layout

    The layout to use.

    configure

    A closure that configures the layout and adds children to the container.

  • Initializes a new ElementContent with the given element and layout.

    Declaration

    Swift

    public init(
        child: Element,
        key: AnyHashable? = nil,
        layout: some SingleChildLayout
    )

    Parameters

    element

    The single child element.

    key

    The key to use to unique the element during updates.

    layout

    The layout that will be used.

Passthrough storage

  • Initializes a new ElementContent with the given element.

    The given element will be used for measuring, and it will always fill the extent of the parent element.

    Declaration

    Swift

    public init(child: Element)

    Parameters

    element

    The single child element.

Lazy storage

Leaf content

  • Initializes a new ElementContent with no children that delegates to the provided Measurable.

    Declaration

    Swift

    public init(measurable: Measurable)

    Parameters

    measurable

    How to measure the ElementContent.

  • Initializes a new ElementContent with no children that delegates to the provided measure function.

    Declaration

    Swift

    public init(
        measureFunction: @escaping (SizeConstraint) -> CGSize
    )

    Parameters

    measureFunction

    How to measure the ElementContent in the given SizeConstraint.

  • Initializes a new ElementContent with no children that delegates to the provided measure function.

    Declaration

    Swift

    public init(
        measureFunction: @escaping (SizeConstraint, Environment) -> CGSize
    )

    Parameters

    measureFunction

    How to measure the ElementContent in the given SizeConstraint and Environment.

  • Initializes a new ElementContent with no children that uses the provided intrinsic size for measuring.

    Declaration

    Swift

    public init(intrinsicSize: CGSize)

Environment adapters

  • Initializes a new ElementContent with the given child element, measurement caching key, and environment adapter, which allows adapting the environment to affect the element, plus elements further down the tree.

    Declaration

    Swift

    public init(
        child: Element,
        environment environmentAdapter: @escaping (inout Environment) -> Void
    )

    Parameters

    child

    The child element to display.

    environmentAdapter

    How to adapt the Environment for the child and elements further down the tree.

  • Initializes a new ElementContent with the given child element, measurement caching key, and environment key + value. which adapts the environment to affect the element, plus elements further down the tree.

    Declaration

    Swift

    public init<Key>(
        child: Element,
        key: Key.Type,
        value: Key.Value
    ) where Key: EnvironmentKey

    Parameters

    child

    The child element to display.

    key

    The key to set in the Environment.

    value

    The value to set in the Environment for the given key.

Nested element measuring

  • Creates a new ElementContent which uses the provided element to measure its size, but does not place the element as a child in the final, laid out hierarchy.

    This is useful if you are placing the element in a nested BlueprintView, for example (eg to create a stateful element) and just need this element to be correctly sized.

    Declaration

    Swift

    public init(measuring element: Element)