| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // 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<V: View>(
- node: AnyViewGraphNode<V>,
- 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<Backend: BaseAppBackend>(
- _ children: Children,
- backend: Backend
- ) -> Backend.Widget {
- let group = Group(content: self)
- return group.asWidget(children, backend: backend)
- }
- @MainActor
- func computeLayout<Backend: BaseAppBackend>(
- _ 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<Backend: BaseAppBackend>(
- _ 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: BaseAppBackend>(
- 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: BaseAppBackend>(
- backend: Backend,
- children: Children
- ) -> [LayoutSystem.LayoutableChild] {
- [
- % for j in range(i + 1):
- layoutableChild(node: children.child${j}, view: view${j}),
- % end
- ]
- }
- }
|