3 public struct PatternPicker: View {
5 @Binding var selectedDesign: TileDesign;
7 var selectedColor: Color = .accentColor
8 var pixelSize: CGFloat = 2.0;
9 var foregroundColor: Color = .black
10 var backgroundColor: Color = .white
12 let patterns = TileDesign.allCases
14 let verticalTileCount = Int(ceil(Double(TileDesign.allCases.count) / 5.0))
16 public var body: some View {
17 VStack(alignment: .leading, spacing: 0) {
18 ForEach(0 ..< verticalTileCount, id: \.self) { i in
19 HStack(alignment: .top, spacing: 0) {
20 ForEach(0 ..< 5) { j in
21 if i * 5 + j < patterns.count {
22 Pattern(design: .constant(patterns[i * 5 + j]), pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor)
23 .frame(width: pixelSize * 16, height: pixelSize * 12)
24 .border(selectedDesign == patterns[i * 5 + j] ? selectedColor : foregroundColor, width: pixelSize / 2.0)
25 .onTapGesture(perform: {
26 selectedDesign = patterns[i * 5 + j]
32 }.background(foregroundColor)
36 struct PatternPicker_Previews: PreviewProvider {
37 static var previews: some View {
40 PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid))
41 Text("Selected color override")
42 PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid),
44 Text("Color override")
45 PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid),
46 foregroundColor: .pink, backgroundColor: .cyan)
47 Text("Pixel size override")
48 PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid), pixelSize: 8.0)