]> git.r.bdr.sh - rbdr/patterns/blob - Sources/Patterns/Pattern.swift
Add readme, update API
[rbdr/patterns] / Sources / Patterns / Pattern.swift
1 import SwiftUI
2
3 public struct Pattern: View {
4
5 private var patternSize: CGFloat {
6 pixelSize * 8.0;
7 }
8
9 @Binding var design: TileDesign;
10 var pixelSize: CGFloat = 2.0;
11 var foregroundColor: Color = .black
12 var backgroundColor: Color = .white
13
14 public var body: some View {
15 GeometryReader { gr in
16 VStack(spacing: 0) {
17 ForEach(0 ..< 1 + Int(ceil(gr.size.height / patternSize)), id: \.self) { i in
18 HStack(spacing: 0) {
19 ForEach(0 ..< Int(ceil(gr.size.width / patternSize)), id: \.self) { j in
20 Tile(design: design, pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor)
21 }
22 }
23 }
24 }
25 }.drawingGroup()
26 }
27 }
28
29 struct Pattern_Previews: PreviewProvider {
30 static var previews: some View {
31 VStack {
32 Text("Default")
33 Pattern(design: .constant(TileDesign.grid))
34 Text("Color override")
35 Pattern(design: .constant(TileDesign.balls), foregroundColor: .pink, backgroundColor: .cyan)
36 Text("Pixel size override")
37 Pattern(design: .constant(TileDesign.shingles), pixelSize: 8.0)
38 }
39 }
40 }