summaryrefslogtreecommitdiff
path: root/makima/ios/Sources/Makima/Design/Components/GridOverlay.swift
blob: 824d0b231b3d0b97e1d32b6b0d0b569abe9dcacb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import SwiftUI

/// Subtle grid, mirrors the makima.jp body background texture.
/// Drawn as a `Canvas` so there's no asset dependency.
struct GridOverlay: View {
    var spacing: CGFloat = 32
    var opacity: Double = 0.04

    var body: some View {
        Canvas { ctx, size in
            let color = GraphicsContext.Shading.color(.white.opacity(opacity))
            var path = Path()
            var x = spacing
            while x < size.width {
                path.move(to: CGPoint(x: x, y: 0))
                path.addLine(to: CGPoint(x: x, y: size.height))
                x += spacing
            }
            var y = spacing
            while y < size.height {
                path.move(to: CGPoint(x: 0, y: y))
                path.addLine(to: CGPoint(x: size.width, y: y))
                y += spacing
            }
            ctx.stroke(path, with: color, lineWidth: 0.5)
        }
        .allowsHitTesting(false)
    }
}