// // VStack.swift // MacBackend // // Created by david-swift on 23.08.23. // import SwiftUI /// A `VStack` view. public struct VStack: SwiftUIWidget, Wrapper { /// The content view. var content: Body /// The wrapped views. public var wrappedViews: [String: Meta.AnyView] { content.enumerated().reduce(into: [:]) { partialResult, element in partialResult["\(element.offset)"] = element.element } } /// Initialize the ``VStack``. /// - Parameter content: The content. public init(@Meta.ViewBuilder content: @escaping () -> Body) { self.content = content() } /// Get the SwiftUI view. /// - Parameter properties: The widget data. /// - Returns: The SwiftUI view. public static func view(properties: Self) -> some SwiftUI.View { SwiftUI.VStack { SwiftUI.ForEach(properties.content.indices, id: \.self) { index in MacBackendView("\(index)") } } } /// The view storage. /// - Parameters: /// - data: Modify views before being updated. /// - type: The view render data type. /// - Returns: The view storage. public func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { if content.count == 1, let storage = content.first?.storage(data: data, type: type) { return storage } return internalContainer(data: data, type: type) } /// Update the stored content. /// - Parameters: /// - storage: The storage to update. /// - data: Modify views before being updated /// - updateProperties: Whether to update the view's properties. /// - type: The view render data type. public func update( _ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type ) where Data: ViewRenderData { if content.count == 1, let first = content.first { first.updateStorage(storage, data: data, updateProperties: updateProperties, type: type) } else { internalUpdate(storage, data: data, updateProperties: updateProperties, type: type) } } }