diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | Sources/Patterns/PatternPicker.swift | 2 | ||||
| -rw-r--r-- | Sources/Patterns/PatternView.swift | 20 |
3 files changed, 12 insertions, 14 deletions
@@ -34,7 +34,7 @@ top left to bottom right) The `PatternView` view will tile the selected design in its frame. It has the following properties: -* `design: Binding<TileDesign>`: **required**, which design to use to tile the +* `design: TileDesign`: **required**, which design to use to tile the frame. * `pixelSize: CGFloat`: **defaults to 2.0**, the size of a pixel in the tile. * `foregroundColor: Color`: **defaults to `Color.black`**, the foreground color. @@ -72,7 +72,7 @@ same effect as `Pattern` mentioned above ... -PatternView(design: $design) +PatternView(design: design) .frame(width: 32.0).border(.black) .onTapGesture { shouldShowPatternPicker = !shouldShowPatternPicker; diff --git a/Sources/Patterns/PatternPicker.swift b/Sources/Patterns/PatternPicker.swift index 32c9f39..46b7ef2 100644 --- a/Sources/Patterns/PatternPicker.swift +++ b/Sources/Patterns/PatternPicker.swift @@ -26,7 +26,7 @@ public struct PatternPicker: View { 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) + PatternView(design: 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: { diff --git a/Sources/Patterns/PatternView.swift b/Sources/Patterns/PatternView.swift index d4ed37b..e95b4df 100644 --- a/Sources/Patterns/PatternView.swift +++ b/Sources/Patterns/PatternView.swift @@ -2,7 +2,7 @@ import SwiftUI public struct PatternView: View { - @Binding public var design: TileDesign + public var design: TileDesign public var pixelSize: CGFloat public var foregroundColor: Color public var backgroundColor: Color @@ -12,8 +12,8 @@ public struct PatternView: View { pixelSize * 8.0; } - public init(design: Binding<TileDesign>, pixelSize: CGFloat = 2.0, foregroundColor: Color = .black, backgroundColor: Color = .white) { - self._design = design + public init(design: TileDesign, pixelSize: CGFloat = 2.0, foregroundColor: Color = .black, backgroundColor: Color = .white) { + self.design = design self.pixelSize = pixelSize self.foregroundColor = foregroundColor self.backgroundColor = backgroundColor @@ -26,13 +26,11 @@ public struct PatternView: View { let backgroundCGColor = NSColor(backgroundColor).cgColor #endif - self.image = TileImage.image(design.wrappedValue, pixelSize: pixelSize, foregroundColor: foregroundCGColor, backgroundColor: backgroundCGColor) + self.image = TileImage.image(design, pixelSize: pixelSize, foregroundColor: foregroundCGColor, backgroundColor: backgroundCGColor) } - public var body: some View { - GeometryReader { gr in - Image(image, scale: 1, label: Text("Test")).resizable(resizingMode: .tile) - }.drawingGroup() + public var body: some View { + Image(image, scale: 1, label: Text("Test")).resizable(resizingMode: .tile).drawingGroup() } } @@ -40,11 +38,11 @@ struct Pattern_Previews: PreviewProvider { static var previews: some View { VStack { Text("Default") - PatternView(design: .constant(TileDesign.grid)) + PatternView(design: TileDesign.grid) Text("Color override") - PatternView(design: .constant(TileDesign.balls), foregroundColor: .pink, backgroundColor: .cyan) + PatternView(design: TileDesign.balls, foregroundColor: .pink, backgroundColor: .cyan) Text("Pixel size override") - PatternView(design: .constant(TileDesign.shingles), pixelSize: 8.0) + PatternView(design: TileDesign.shingles, pixelSize: 8.0) } } } |