Sources/OrgApp/ColumnViewGrid.swift

design-themes-widgets
orgstar/Sources/OrgApp/ColumnViewGrid.swift history · blame · raw

31 lines · 1075 bytes

 1import OrgCore
 2import SwiftUI
 3
 4/// `org-columns` laid out: a row of column titles, a rule, then a row per entry, each cell from `cell(row, column)`.
 5public struct ColumnViewGrid<Cell: View>: View {
 6    let view: ColumnView.View
 7    let verticalSpacing: CGFloat
 8    let cell: (Int, Int) -> Cell
 9
10    public init(view: ColumnView.View, verticalSpacing: CGFloat, @ViewBuilder cell: @escaping (Int, Int) -> Cell) {
11        self.view = view
12        self.verticalSpacing = verticalSpacing
13        self.cell = cell
14    }
15
16    public var body: some View {
17        Grid(alignment: .leading, horizontalSpacing: 14, verticalSpacing: verticalSpacing) {
18            GridRow {
19                ForEach(view.specs.indices, id: \.self) { i in
20                    Text(view.specs[i].title).bold().foregroundStyle(.secondary)
21                }
22            }
23            Divider()
24            ForEach(view.rows.indices, id: \.self) { r in
25                GridRow {
26                    ForEach(view.specs.indices, id: \.self) { c in cell(r, c) }
27                }
28            }
29        }
30    }
31}