From 23e47cd8c0e84d68b8d53724b66a0274a6b9cb71 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Wed, 16 Apr 2025 23:33:04 +0200 Subject: Don't use binding for PatternView --- Sources/Patterns/PatternView.swift | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'Sources/Patterns/PatternView.swift') 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, 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) } } } -- cgit