3 public struct PatternView: View {
5 @Binding public var design: TileDesign
6 public var pixelSize: CGFloat
7 public var foregroundColor: Color
8 public var backgroundColor: Color
10 private var patternSize: CGFloat {
14 public init(design: Binding<TileDesign>, pixelSize: CGFloat = 2.0, foregroundColor: Color = .black, backgroundColor: Color = .white) {
16 self.pixelSize = pixelSize
17 self.foregroundColor = foregroundColor
18 self.backgroundColor = backgroundColor
21 public var body: some View {
22 GeometryReader { gr in
24 ForEach(0 ..< 1 + Int(ceil(gr.size.height / patternSize)), id: \.self) { i in
26 ForEach(0 ..< Int(ceil(gr.size.width / patternSize)), id: \.self) { j in
27 Tile(design: design, pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor)
36 struct Pattern_Previews: PreviewProvider {
37 static var previews: some View {
40 PatternView(design: .constant(TileDesign.grid))
41 Text("Color override")
42 PatternView(design: .constant(TileDesign.balls), foregroundColor: .pink, backgroundColor: .cyan)
43 Text("Pixel size override")
44 PatternView(design: .constant(TileDesign.shingles), pixelSize: 8.0)