macbackend/Sources/Core/View/ToolbarView.swift
david-swift 43f53e1681
All checks were successful
Deploy Docs / publish (push) Successful in 2m59s
SwiftLint / SwiftLint (push) Successful in 2s
Add support for toolbars
2024-12-08 20:39:50 +01:00

47 lines
1.2 KiB
Swift

//
// ToolbarView.swift
// MacBackend
//
// Created by david-swift on 08.12.2024.
//
import SwiftUI
/// The padding view.
public struct ToolbarView: SwiftUIWidget {
/// The wrapped view.
var child: Meta.AnyView
/// The toolbar views.
var toolbarViews: Body
/// The wrapped views.
public var wrappedViews: [String: Meta.AnyView] {
[.mainContent: child].merging(toolbarViews.enumerated().reduce(into: [:]) { partialResult, view in
partialResult["\(view.offset)"] = view.element
}) { $1 }
}
/// Initialize the padding view.
/// - Parameters:
/// - child: The wrapped view.
/// - toolbarViews: The views in the toolbar.
public init(child: Meta.AnyView, @Meta.ViewBuilder toolbarViews: () -> Body) {
self.child = child
self.toolbarViews = toolbarViews()
}
/// Get the SwiftUI view.
/// - Parameter properties: The widget data.
/// - Returns: The SwiftUI view.
public static func view(properties: Self) -> some SwiftUI.View {
MacBackendView(.mainContent)
.toolbar {
ForEach(properties.toolbarViews.indices, id: \.self) { index in
MacBackendView("\(index)")
}
}
}
}