From 1418fe49617f5d35b14b19fe0ead15fcc43526c8 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Wed, 26 Apr 2023 17:10:19 +0200 Subject: Add readme, update API --- Sources/Patterns/Pattern.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Sources/Patterns/Pattern.swift') diff --git a/Sources/Patterns/Pattern.swift b/Sources/Patterns/Pattern.swift index 1951888..4fbc528 100644 --- a/Sources/Patterns/Pattern.swift +++ b/Sources/Patterns/Pattern.swift @@ -1,14 +1,15 @@ import SwiftUI public struct Pattern: View { - - private let pixelSize: CGFloat = 2.0; private var patternSize: CGFloat { pixelSize * 8.0; } @Binding var design: TileDesign; + var pixelSize: CGFloat = 2.0; + var foregroundColor: Color = .black + var backgroundColor: Color = .white public var body: some View { GeometryReader { gr in @@ -16,7 +17,7 @@ public struct Pattern: View { ForEach(0 ..< 1 + Int(ceil(gr.size.height / patternSize)), id: \.self) { i in HStack(spacing: 0) { ForEach(0 ..< Int(ceil(gr.size.width / patternSize)), id: \.self) { j in - Tile(design: design) + Tile(design: design, pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor) } } } @@ -27,6 +28,13 @@ public struct Pattern: View { struct Pattern_Previews: PreviewProvider { static var previews: some View { - Pattern(design: .constant(TileDesign.grid)) + VStack { + Text("Default") + Pattern(design: .constant(TileDesign.grid)) + Text("Color override") + Pattern(design: .constant(TileDesign.balls), foregroundColor: .pink, backgroundColor: .cyan) + Text("Pixel size override") + Pattern(design: .constant(TileDesign.shingles), pixelSize: 8.0) + } } } -- cgit