]> git.r.bdr.sh - rbdr/patterns/blame - Sources/Patterns/Pattern.swift
Add supported platforms
[rbdr/patterns] / Sources / Patterns / Pattern.swift
CommitLineData
8b0b5b39
RBR
1import SwiftUI
2
3public struct Pattern: View {
cd8a7cf4
RBR
4
5 @Binding public var design: TileDesign;
6 public var pixelSize: CGFloat = 2.0;
7 public var foregroundColor: Color = .black
8 public var backgroundColor: Color = .white
8b0b5b39
RBR
9
10 private var patternSize: CGFloat {
11 pixelSize * 8.0;
12 }
13
8b0b5b39
RBR
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
1418fe49 20 Tile(design: design, pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor)
8b0b5b39
RBR
21 }
22 }
23 }
24 }
25 }.drawingGroup()
26 }
27}
28
29struct Pattern_Previews: PreviewProvider {
30 static var previews: some View {
1418fe49
RBR
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 }
8b0b5b39
RBR
39 }
40}