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.swift25
1 files changed, 14 insertions, 11 deletions
diff --git a/Sources/Patterns/PatternView.swift b/Sources/Patterns/PatternView.swift
index be78bde..d4ed37b 100644
--- a/Sources/Patterns/PatternView.swift
+++ b/Sources/Patterns/PatternView.swift
@@ -7,28 +7,31 @@ public struct PatternView: View {
public var foregroundColor: Color
public var backgroundColor: Color
+ private let image: CGImage
private var patternSize: CGFloat {
pixelSize * 8.0;
}
-
+
public init(design: Binding<TileDesign>, pixelSize: CGFloat = 2.0, foregroundColor: Color = .black, backgroundColor: Color = .white) {
self._design = design
self.pixelSize = pixelSize
self.foregroundColor = foregroundColor
self.backgroundColor = backgroundColor
+
+ #if os(iOS) || os(watchOS) || os(tvOS)
+ let foregroundCGColor = UIColor(foregroundColor).cgColor
+ let backgroundCGColor = UIColor(backgroundColor).cgColor
+ #else
+ let foregroundCGColor = NSColor(foregroundColor).cgColor
+ let backgroundCGColor = NSColor(backgroundColor).cgColor
+ #endif
+
+ self.image = TileImage.image(design.wrappedValue, pixelSize: pixelSize, foregroundColor: foregroundCGColor, backgroundColor: backgroundCGColor)
}
-
+
public var body: some View {
GeometryReader { gr in
- VStack(spacing: 0) {
- ForEach(0 ..< 1 + Int(ceil(gr.size.height / patternSize)), id: \.self) { i in
- HStack(spacing: 0) {
- ForEach(0 ..< Int(ceil(gr.size.width / patternSize)), id: \.self) { j in
- Tile(design: design, pixelSize: pixelSize, foregroundColor: foregroundColor, backgroundColor: backgroundColor)
- }
- }
- }
- }
+ Image(image, scale: 1, label: Text("Test")).resizable(resizingMode: .tile)
}.drawingGroup()
}
}