// This file was generated using gyb. Do not edit it directly. Edit // TupleView.swift.gyb instead. // swiftformat:options --allow-partial-wrapping true %{ maximum_view_count = 20 }% @MainActor private func layoutableChild( node: AnyViewGraphNode, view: V ) -> LayoutSystem.LayoutableChild { LayoutSystem.LayoutableChild( computeLayout: { proposedSize, environment in node.computeLayout( with: view, proposedSize: proposedSize, environment: environment ) }, commit: { node.commit() }, tag: "\(type(of: view))" ) } /// Just a vessel for some default implementations to compress this generated code. @MainActor protocol TupleView: TypeSafeView {} extension TupleView { @MainActor func asWidget( _ children: Children, backend: Backend ) -> Backend.Widget { let group = Group(content: self) return group.asWidget(children, backend: backend) } @MainActor func computeLayout( _ widget: Backend.Widget, children: Children, proposedSize: ProposedViewSize, environment: EnvironmentValues, backend: Backend ) -> ViewLayoutResult { let group = Group(content: self) return group.computeLayout( widget, children: children, proposedSize: proposedSize, environment: environment, backend: backend ) } @MainActor func commit( _ widget: Backend.Widget, children: Children, layout: ViewLayoutResult, environment: EnvironmentValues, backend: Backend ) { let group = Group(content: self) group.commit( widget, children: children, layout: layout, environment: environment, backend: backend ) } } % for i in range(maximum_view_count): %{ view = "TupleView%d" % (i + 1) struct_parameters = ", ".join(["View%d: View" % (j) for j in range(i + 1)]) properties = "\n ".join(["public var view%d: View%d" % (j, j) for j in range(i + 1)]) init_parameters = ", ".join(["_ view%d: View%d" % (j, j) for j in range(i + 1)]) init_body = "\n ".join(["self.view%d = view%d" % (j, j) for j in range(i + 1)]) children_type_parameters = ", ".join(["View%d" % j for j in range(i + 1)]) }% /// A view with exactly ${i + 1} children. Autogenerated as an alternative to Swift's not yet /// production ready variadic generics. /// /// Has the same behaviour as ``Group`` when rendered directly. public struct ${view}< ${struct_parameters} > { ${properties} public var body = EmptyView() /// Wraps ${i + 1} child views in a single container view. public init( ${init_parameters} ) { ${init_body} } } extension ${view}: View { public typealias Content = EmptyView public var _asMenuItems: [MenuItem] { var result: [MenuItem] = [] % for j in range(i + 1): result += view${j}._asMenuItems % end return result } } extension ${view}: TupleView { typealias Children = TupleViewChildren${i + 1}<${children_type_parameters}> func children( backend: Backend, snapshots: [ViewGraphSnapshotter.NodeSnapshot]?, environment: EnvironmentValues ) -> Children { return Children( ${" ".join("view%d," % j for j in range(i + 1))} backend: backend, snapshots: snapshots, environment: environment ) } func layoutableChildren( backend: Backend, children: Children ) -> [LayoutSystem.LayoutableChild] { [ % for j in range(i + 1): layoutableChild(node: children.child${j}, view: view${j}), % end ] } }