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