]>
Commit | Line | Data |
---|---|---|
1 | import SwiftUI | |
2 | ||
3 | public struct Pattern: View { | |
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 | |
9 | ||
10 | private var patternSize: CGFloat { | |
11 | pixelSize * 8.0; | |
12 | } | |
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 | } |