]>
Commit | Line | Data |
---|---|---|
8b0b5b39 RBR |
1 | import SwiftUI |
2 | ||
3 | public struct Pattern: View { | |
8b0b5b39 RBR |
4 | |
5 | private var patternSize: CGFloat { | |
6 | pixelSize * 8.0; | |
7 | } | |
8 | ||
9 | @Binding var design: TileDesign; | |
1418fe49 RBR |
10 | var pixelSize: CGFloat = 2.0; |
11 | var foregroundColor: Color = .black | |
12 | var backgroundColor: Color = .white | |
8b0b5b39 RBR |
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 | |
1418fe49 | 20 | Tile(design: design, pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor) |
8b0b5b39 RBR |
21 | } |
22 | } | |
23 | } | |
24 | } | |
25 | }.drawingGroup() | |
26 | } | |
27 | } | |
28 | ||
29 | struct 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 | } |