diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-16 20:13:38 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-16 20:13:38 +0200 |
| commit | 4f0a1f57cdc6cd03751f043c102d7f708d573902 (patch) | |
| tree | 8eea3f65b99e5ffc0cd757ac8cd38d3999a54b4e | |
| parent | ba4ee0edf2aba19ad73fa53cb01dd0fb9b527526 (diff) | |
Don't use binding for pattern, update swift versiontesting-as-bg
| -rw-r--r-- | Package.swift | 12 | ||||
| -rw-r--r-- | Sources/Patterns/PatternPicker.swift | 31 | ||||
| -rw-r--r-- | Sources/Patterns/PatternView.swift | 43 |
3 files changed, 47 insertions, 39 deletions
diff --git a/Package.swift b/Package.swift index 2fa3f21..f63b77c 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.8 +// swift-tools-version: 6.1 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -6,11 +6,11 @@ import PackageDescription let package = Package( name: "Patterns", platforms: [ - .macOS(.v12), - .iOS(.v15), - .macCatalyst(.v15), - .tvOS(.v16), - .watchOS(.v8) + .macOS(.v14), + .iOS(.v17), + .macCatalyst(.v17), + .tvOS(.v17), + .watchOS(.v10) ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. diff --git a/Sources/Patterns/PatternPicker.swift b/Sources/Patterns/PatternPicker.swift index 32c9f39..c519c88 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: { @@ -40,19 +40,18 @@ public struct PatternPicker: View { } } -struct PatternPicker_Previews: PreviewProvider { - static var previews: some View { - VStack { - Text("Default") - PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid)) - Text("Selected color override") - PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid), - selectedColor: .red) - Text("Color override") - PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid), - foregroundColor: .pink, backgroundColor: .cyan) - Text("Pixel size override") - PatternPicker(selectedDesign: .constant(TileDesign.shadowGrid), pixelSize: 8.0) - } - } +#Preview { + + @Previewable @State var selectedDesign: TileDesign = .shadowGrid + + Text("Default") + PatternPicker(selectedDesign: $selectedDesign) + Text("Selected color override") + PatternPicker(selectedDesign: $selectedDesign, + selectedColor: .red) + Text("Color override") + PatternPicker(selectedDesign: $selectedDesign, + foregroundColor: .pink, backgroundColor: .cyan) + Text("Pixel size override") + PatternPicker(selectedDesign: $selectedDesign, pixelSize: 8.0) } diff --git a/Sources/Patterns/PatternView.swift b/Sources/Patterns/PatternView.swift index d4ed37b..a2be495 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,25 +26,34 @@ 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() + Image(image, scale: 1, label: Text("Test")).resizable(resizingMode: .tile).drawingGroup() } } -struct Pattern_Previews: PreviewProvider { - static var previews: some View { - VStack { - Text("Default") - PatternView(design: .constant(TileDesign.grid)) - Text("Color override") - PatternView(design: .constant(TileDesign.balls), foregroundColor: .pink, backgroundColor: .cyan) - Text("Pixel size override") - PatternView(design: .constant(TileDesign.shingles), pixelSize: 8.0) +#Preview { + + @Previewable @State var design: TileDesign = .grid + + VStack { + Text("Default") + PatternView(design: TileDesign.grid) + Text("Color override") + PatternView(design: TileDesign.balls, foregroundColor: .pink, backgroundColor: .cyan) + Text("Pixel size override") + PatternView(design: TileDesign.shingles, pixelSize: 8.0) + Text("Redraw on change") + PatternView(design: design) + .onAppear { + withAnimation( + .linear(duration: 2.0) + .repeatForever() + ) { + design = .balls + } } - } + } } |