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/Tile.swift | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'Sources/Patterns/Tile.swift') diff --git a/Sources/Patterns/Tile.swift b/Sources/Patterns/Tile.swift index c27fcf9..3893324 100644 --- a/Sources/Patterns/Tile.swift +++ b/Sources/Patterns/Tile.swift @@ -1,16 +1,17 @@ import SwiftUI -struct Tile: View { - - let pixelSize: CGFloat = 2.0; +public struct Tile: View { let design: TileDesign + var pixelSize: CGFloat = 2.0; + var foregroundColor: Color = .black + var backgroundColor: Color = .white private var pixels: [Int] { design.pixels() } - var body: some View { + public var body: some View { VStack(spacing: 0) { ForEach(0 ..< 8) { i in HStack(spacing: 0) { @@ -18,8 +19,8 @@ struct Tile: View { Rectangle() .frame(width: pixelSize, height: pixelSize) .foregroundColor(pixels[(i % 8) * 8 + j % 8] == 0 - ? .black - : .white + ? foregroundColor + : backgroundColor ) } } @@ -30,6 +31,13 @@ struct Tile: View { struct Tile_Previews: PreviewProvider { static var previews: some View { - Tile(design: .grid) + VStack { + Text("Default") + Tile(design: .grid) + Text("Color override") + Tile(design: .balls, foregroundColor: .pink, backgroundColor: .cyan) + Text("Pixel size override") + Tile(design: .shingles, pixelSize: 8.0) + } } } -- cgit