// Ruled lines for typing on: a pencil hairline every `pitch` points, drawn // behind a multi-line field so the words sit on the paper's own lines. The // field sets its line spacing so one typed line is one pitch. import SwiftUI struct RuledLines: View { @Environment(\.theme) private var theme /// The distance between two rules — one typed line at 15pt with its /// spacing (`paper_ruled_line_pitch`). private var pitch: CGFloat { RuledLinesKnobs.paperRuledLinePitch } // The line spacing a 15pt typewriter field needs to land on the rules is // the worn theme's `paper_ruled_typed_spacing`, which the field reads. var body: some View { Canvas { context, size in var y = pitch while y <= size.height { var line = Path() line.move(to: CGPoint(x: 0, y: y)) line.addLine(to: CGPoint(x: size.width, y: y)) context.stroke( line, with: .color(theme.print(.pencil).opacity(Double(RuledLinesKnobs.paperRuledLineOpacity))), lineWidth: theme.scale.hairline ) y += pitch } } .accessibilityHidden(true) } } /// The sizes, counts and timings RuledLines draws with: Swift's own, beside /// their reader — a theme sets only its tokens (`scale.tokens`). enum RuledLinesKnobs { static let paperRuledLineOpacity: CGFloat = 0.3 static let paperRuledLinePitch: CGFloat = 26 }