aboutsummaryrefslogtreecommitdiff
path: root/Sources/Patterns/PatternView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Sources/Patterns/PatternView.swift')
-rw-r--r--Sources/Patterns/PatternView.swift43
1 files changed, 26 insertions, 17 deletions
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
+ }
}
- }
+ }
}