X-Git-Url: https://git.r.bdr.sh/rbdr/patterns/blobdiff_plain/cd8a7cf4a8dd77e11184202f6b67161383942652..5c40e23a9b05b53186995c73125fae5062ab73bf:/Sources/Patterns/PatternPicker.swift?ds=sidebyside diff --git a/Sources/Patterns/PatternPicker.swift b/Sources/Patterns/PatternPicker.swift index 3f550e5..32c9f39 100644 --- a/Sources/Patterns/PatternPicker.swift +++ b/Sources/Patterns/PatternPicker.swift @@ -4,33 +4,40 @@ public struct PatternPicker: View { @Binding public var selectedDesign: TileDesign; - public var selectedColor: Color = .accentColor - public var pixelSize: CGFloat = 2.0; - public var foregroundColor: Color = .black - public var backgroundColor: Color = .white + public var selectedColor: Color + public var pixelSize: CGFloat + public var foregroundColor: Color + public var backgroundColor: Color - let patterns = TileDesign.allCases - - let verticalTileCount = Int(ceil(Double(TileDesign.allCases.count) / 5.0)) + public init(selectedDesign: Binding, selectedColor: Color = .accentColor, pixelSize: CGFloat = 2.0, foregroundColor: Color = .black, backgroundColor: Color = .white) { + self._selectedDesign = selectedDesign + self.selectedColor = selectedColor + self.pixelSize = pixelSize + self.foregroundColor = foregroundColor + self.backgroundColor = backgroundColor + } + + private let patterns = TileDesign.allCases + private let verticalTileCount = Int(ceil(Double(TileDesign.allCases.count) / 5.0)) - public var body: some View { - VStack(alignment: .leading, spacing: 0) { - ForEach(0 ..< verticalTileCount, id: \.self) { i in - HStack(alignment: .top, spacing: 0) { - ForEach(0 ..< 5) { j in - if i * 5 + j < patterns.count { - Pattern(design: .constant(patterns[i * 5 + j]), pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor) - .frame(width: pixelSize * 16, height: pixelSize * 12) - .border(selectedDesign == patterns[i * 5 + j] ? selectedColor : foregroundColor, width: pixelSize / 2.0) - .onTapGesture(perform: { - selectedDesign = patterns[i * 5 + j] - }) - } + public var body: some View { + VStack(alignment: .leading, spacing: 0) { + ForEach(0 ..< verticalTileCount, id: \.self) { i in + HStack(alignment: .top, spacing: 0) { + ForEach(0 ..< 5) { j in + if i * 5 + j < patterns.count { + PatternView(design: .constant(patterns[i * 5 + j]), pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor) + .frame(width: pixelSize * 16, height: pixelSize * 12) + .border(selectedDesign == patterns[i * 5 + j] ? selectedColor : foregroundColor, width: pixelSize / 2.0) + .onTapGesture(perform: { + selectedDesign = patterns[i * 5 + j] + }) } } } - }.background(foregroundColor) - } + } + }.background(foregroundColor) + } } struct PatternPicker_Previews: PreviewProvider {