// The todo's check, and the line along a check slip's foot — drawn by every // slip whose definition names a toggle (`SlipFace`) and the project // overview's todo rows. // // They lived with the Todos tool's board card until the Todos screens became // their table's list and page (rebuild item 4); the card went, the check and // the foot it shared stay here. import SwiftUI // MARK: - The slip's foot /// What the board's slip types along its foot, and the two sizes it lays. /// /// Pure, so the sentence a person reads under a todo is settled by a test /// rather than by reading a view body. enum TodoSlipFoot { /// The day, the time and the project, in that order, joined by the page's /// separator — or nothing at all when the slip carries none of them. On /// an upcoming list the day is left to its heading (`upcomingFoot`); the /// project is always said, since no heading names it. static func line(day: String?, meta: String?, project: String? = nil) -> String? { let parts = [day, meta, project] .compactMap { $0 } .filter { !$0.isEmpty } return parts.isEmpty ? nil : parts.joined(separator: " \u{00B7} ") } } // MARK: - The check /// The check on a slip's paper — every check slip's, ONE view, so a todo's /// check is the same object wherever it is drawn. /// /// A square, 1.5pt stroke, radius 3; done draws the red tick over it, /// overshooting the square the way a pen does. Its own control, with the 44pt /// target a thumb needs, laid out at the square's own size. struct TodoPaperCheck: View { let done: Bool let side: CGFloat /// What the todo is called, for the spoken "Complete …" / "Reopen …". let label: String /// `true` to complete, `false` to reopen. let onToggle: (Bool) -> Void @Environment(\.cottonHaptics) private var haptics @Environment(\.theme) private var theme var body: some View { Button { done ? haptics.select() : haptics.success() onToggle(!done) } label: { TodoCheckSquare(done: done, side: side) .padding((SlipCheckKnobs.slipCheckTarget - side) * 0.5) .contentShape(Rectangle()) } .buttonStyle(.plain) .padding(-(SlipCheckKnobs.slipCheckTarget - side) * 0.5) .accessibilityLabel(ShellLines.line("faces", done ? "slip.reopen" : "slip.complete", ["label": label])) .accessibilityAddTraits(done ? [.isButton, .isSelected] : .isButton) } } /// The check's drawing and nothing else: a square, 1.5pt stroke, radius 3, /// and done's red tick over it. The board's check wraps it in a control. struct TodoCheckSquare: View { @Environment(\.theme) private var theme let done: Bool let side: CGFloat var body: some View { ZStack { RoundedRectangle(cornerRadius: SlipCheckKnobs.slipCheckCornerRadius, style: .continuous) .strokeBorder(theme.print(.ink), lineWidth: SlipCheckKnobs.slipCheckLineWidth) .blendMode(theme.printBlend) if done { HandTick(theme: theme) .stroke( theme.print(.red), style: StrokeStyle(lineWidth: max(SlipCheckKnobs.slipCheckTickMinWidth, side * SlipCheckKnobs.slipCheckTickWidthFraction), lineCap: .round, lineJoin: .round) ) .frame(width: side * SlipCheckKnobs.slipCheckTickWidthRatio, height: side * SlipCheckKnobs.slipCheckTickHeightRatio) .offset(x: side * SlipCheckKnobs.slipCheckTickOffsetXRatio, y: -side * SlipCheckKnobs.slipCheckTickOffsetYRatio) } } .frame(width: side, height: side) } } /// The sizes, counts and timings SlipCheck draws with: Swift's own, beside /// their reader — a theme sets only its tokens (`scale.tokens`). enum SlipCheckKnobs { static let slipCheckCornerRadius: CGFloat = 3 static let slipCheckLineWidth: CGFloat = 1.5 static let slipCheckTarget: CGFloat = 44 static let slipCheckTickHeightRatio: CGFloat = 1.33 static let slipCheckTickMinWidth: CGFloat = 2.5 static let slipCheckTickOffsetXRatio: CGFloat = 0.17 static let slipCheckTickOffsetYRatio: CGFloat = 0.33 static let slipCheckTickWidthFraction: CGFloat = 0.12 static let slipCheckTickWidthRatio: CGFloat = 1.22 }