]>
Commit | Line | Data |
---|---|---|
8b0b5b39 RBR |
1 | import SwiftUI |
2 | ||
1418fe49 | 3 | public struct Tile: View { |
8b0b5b39 RBR |
4 | |
5 | let design: TileDesign | |
1418fe49 RBR |
6 | var pixelSize: CGFloat = 2.0; |
7 | var foregroundColor: Color = .black | |
8 | var backgroundColor: Color = .white | |
8b0b5b39 RBR |
9 | |
10 | private var pixels: [Int] { | |
11 | design.pixels() | |
12 | } | |
13 | ||
1418fe49 | 14 | public var body: some View { |
8b0b5b39 RBR |
15 | VStack(spacing: 0) { |
16 | ForEach(0 ..< 8) { i in | |
17 | HStack(spacing: 0) { | |
18 | ForEach(0 ..< 8) { j in | |
19 | Rectangle() | |
20 | .frame(width: pixelSize, height: pixelSize) | |
21 | .foregroundColor(pixels[(i % 8) * 8 + j % 8] == 0 | |
1418fe49 RBR |
22 | ? foregroundColor |
23 | : backgroundColor | |
8b0b5b39 RBR |
24 | ) |
25 | } | |
26 | } | |
27 | } | |
28 | } | |
29 | } | |
30 | } | |
31 | ||
32 | struct Tile_Previews: PreviewProvider { | |
33 | static var previews: some View { | |
1418fe49 RBR |
34 | VStack { |
35 | Text("Default") | |
36 | Tile(design: .grid) | |
37 | Text("Color override") | |
38 | Tile(design: .balls, foregroundColor: .pink, backgroundColor: .cyan) | |
39 | Text("Pixel size override") | |
40 | Tile(design: .shingles, pixelSize: 8.0) | |
41 | } | |
8b0b5b39 RBR |
42 | } |
43 | } |