// The red ink ring round a card's corner: the corner's words ringed by hand// (`RingedCorner`, an event's, a subscription's, a transaction's "why now"),// and the ring itself (`CornerRing`) the deck circles an open date corner// with while it is edited in place (CottonUI's `DeckEditable`).importCottonPaperimportSwiftUIenumCornerRingKnobs {/// The corner's words, and the ring's reach round them.staticlet wordsSize: CGFloat = 14staticlet ringPad = EdgeInsets(top: 12, leading: 20, bottom: 12, trailing: 20)staticlet stroke: CGFloat = 1.6}/// The corner's words typed and ringed by hand in red.publicstructRingedCorner: View {let words: Stringvar pressing = falsepublicinit(words: String, pressing: Bool = false) {self.words = wordsself.pressing = pressing }publicvar body: someView {Text(words) .font(CottonFonts.type(CornerRingKnobs.wordsSize)) .lineLimit(1) .faceInk(pressing ? .red : .ink) .padding(CornerRingKnobs.ringPad) .background(CornerRing()) .rotationEffect(.degrees(-3)) .accessibilityIdentifier("face-corner") }}/// The red ink ring round an open corner (image 4): Card design's drawn ring/// when it is in the catalogue, else a ring drawn by hand in code — two/// passes of a pen that does not quite close.publicstructCornerRing: View { @Environment(\.theme) privatevar themepublicinit() {}publicvar body: someView {iflet ring = CottonMedia.image("edit-corner-ring") { ring.resizable() .blendMode(theme.printBlend) } else { ZStack {PenRing(start: 0.06, sweep: 1.04, tilt: -2.5) .stroke(theme.print(.red), style: StrokeStyle(lineWidth: CornerRingKnobs.stroke, lineCap: .round))PenRing(start: 0.55, sweep: 0.62, tilt: -1, squash: 0.94) .stroke(theme.print(.red).opacity(0.7), style: StrokeStyle(lineWidth: CornerRingKnobs.stroke * 0.7, lineCap: .round)) } .blendMode(theme.printBlend) } }}/// One pass of a pen round an ellipse: from `start` (in turns) for `sweep`/// turns, the ellipse leant by `tilt` degrees, its height `squash` of the box.structPenRing: Shape {var start: Doublevar sweep: Doublevar tilt: Doublevar squash: Double = 1func path(in rect: CGRect) -> Path {var path = Path()let centre = CGPoint(x: rect.midX, y: rect.midY)let rx = rect.width / 2, ry = rect.height / 2 * squashlet lean = tilt * .pi / 180let steps = 72for step in0...steps {let turn = start + sweep * Double(step) / Double(steps)let angle = turn * 2 * .pi// The pen drifts outward as it goes, so the ends do not meet.let drift = 1 + 0.035 * Double(step) / Double(steps)let x = cos(angle) * rx * drift, y = sin(angle) * ry * driftlet point = CGPoint(x: centre.x + x * cos(lean) - y * sin(lean), y: centre.y + x * sin(lean) + y * cos(lean))if step == 0 { path.move(to: point) } else { path.addLine(to: point) } }return path }}