macbackend/Sources/Core/View/HStack.swift
david-swift b17f05a6a0
All checks were successful
Deploy Docs / publish (push) Successful in 3m39s
SwiftLint / SwiftLint (push) Successful in 5s
Add support for ForEach
2024-12-31 09:55:02 +01:00

41 lines
996 B
Swift

//
// HStack.swift
// MacBackend
//
// Created by david-swift on 05.12.2024.
//
import SwiftUI
/// A `HStack` view.
public struct HStack: SwiftUIWidget {
/// 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 ``HStack``.
/// - 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.HStack {
SwiftUI.ForEach(properties.content.indices, id: \.self) { index in
MacBackendView("\(index)")
}
}
}
}