Cotton code
408 lines · 18.5 KB · SwiftRaw
// Where a tool's name is PRINTED on its own object — Home's directory.//// The owner's ruling of 2026-09-16: Home's objects carry no word under them// and no figure. The name is printed ON the object's face — on the clipboard's// header, on the ledger's cover, across the newspaper's masthead — set LIVE// and blended into the photograph exactly the way a project's name is printed// on an enamel cap (`ProjectCaps.swift`: the ink is `PrintInk`, multiplied// when it is dark and screened when it is cream, so the object's own grain and// wear show through the letters). Nothing is baked into a PNG: a rename is a// redraw, and the calendar reprints itself every day.//// ONE ENTRY PER OBJECT, keyed by the OBJECT's name — the part after `tool-`,// which is what `ToolObjects.asset(for:)` names. The entry says WHERE on the// 600 × 600 cut-out the print sits (a box in unit coordinates of the square),// at what angle, in which face and which paint.//// AND THE OBJECTS THAT CARRY NO WORD. A telephone handset, a dartboard, a map// with a pin, a film reel: they have no printable face, and they do not need// one — they say what they are. They are `wordless`, and the two sets are// TOTAL and DISJOINT over `ToolObjects.objectNames`: an object in neither// would silently lose its name, and one in both is two rules for one object.// `ToolPrintTests` holds both directions.//// THE CALENDAR PRINTS THE DATE, NOT THE WORD. A tear-off calendar with// "Calendar" typed on it is a label; a tear-off calendar with SEP over a 16 is// a calendar. Its table entry is the DAY's box; the month band above it is// `calendarMonth`, and both are read off the `now` Home already holds, through// `CottonDate`'s pinned formatter and never an ad-hoc one.import CottonKitimport CottonValuesimport Foundationimport SwiftUI/// One object's print.public struct ToolPrint: Sendable, Equatable {    /// The faces a print can be set in — the bundled ones (`Fonts.swift`),    /// which is the whole vocabulary an object's lettering has.    public enum Face: String, CaseIterable, Sendable {        /// Courier Prime — typing on a form, a label, a card.        case type        /// Instrument Serif Italic — the enamel lettering, a bottler's label.        case cap        /// Fraunces Title — a masthead, a spine, a cover.        case display        /// Caveat — a hand that wrote on the thing itself.        case hand        public func font(_ size: CGFloat, in type: ThemeType) -> Font {            switch self {            case .type: return type.body(size)            case .cap: return type.cap(size)            case .display: return type.display(size)            case .hand: return type.hand(size)            }        }    }    /// What the print does to the name before it sets it. Not a style — a    /// ledger's cover is STAMPED in capitals and a note's is not, and that is    /// a fact about the object, not about the string.    public enum Transform: String, CaseIterable, Sendable {        case none, upper        public func apply(_ text: String) -> String {            switch self {            case .none: return text            case .upper: return text.uppercased()            }        }    }    /// The two paints — `ProjectCaps.swift`'s, so a cream is one cream.    public typealias Ink = PrintInk    /// Centre of the print box in unit coordinates of the object's square    /// (0…1, origin top-left).    public let cx: CGFloat    public let cy: CGFloat    /// Width and height of the print box, as fractions of the square's side.    public let w: CGFloat    public let h: CGFloat    /// Rotation of the print, degrees, clockwise positive.    public let rotation: CGFloat    public let face: Face    public let ink: Ink    public let transform: Transform    /// How many lines the box may wrap to — 1 or 2, for the long names.    public let lines: Int    public init(        cx: CGFloat,        cy: CGFloat,        w: CGFloat,        h: CGFloat,        rotation: CGFloat = 0,        face: Face,        ink: Ink = .dark,        transform: Transform = .none,        lines: Int = 1    ) {        self.cx = cx        self.cy = cy        self.w = w        self.h = h        self.rotation = rotation        self.face = face        self.ink = ink        self.transform = transform        self.lines = lines    }    /// The point size this print is set at on an object drawn `objectSide`    /// points wide. The box is the measure, not the cell: an object is the    /// same picture at every size, so its lettering scales with the picture.    /// One line fills `tool_print_font_fraction` of the box's height.    public func fontSize(objectSide: CGFloat, scale: ThemeScale) -> CGFloat {        objectSide * h * ToolPrintKnobs.toolPrintFontFraction / CGFloat(max(lines, 1))    }    /// The box's size in points on an object drawn `objectSide` points wide.    public func size(objectSide: CGFloat) -> CGSize {        CGSize(width: objectSide * w, height: objectSide * h)    }    /// The box's centre as an offset from the object's centre, in points.    public func offset(objectSide: CGFloat) -> CGSize {        CGSize(width: (cx - 0.5) * objectSide, height: (cy - 0.5) * objectSide)    }}extension ToolPrint {    /// The object whose print is the DATE.    public static let calendarObject = "calendar"    /// The month band over the calendar's pad — the second print the only    /// two-print object carries. Its day number is `table["calendar"]`.    public static func calendarMonth(in scale: ThemeScale) -> ToolPrint {        ToolPrint(            cx: ToolPrintKnobs.toolPrintCalendarMonthCx, cy: ToolPrintKnobs.toolPrintCalendarMonthCy,            w: ToolPrintKnobs.toolPrintCalendarMonthW, h: ToolPrintKnobs.toolPrintCalendarMonthH,            face: .type, transform: .upper        )    }    /// Today, as the pad prints it: the short month in capitals over the day    /// number. `en_US_POSIX` and an explicit pattern, through `CottonDate` —    /// the app's spellings are the app's, never the device locale's    /// (`Format/DateFormats.swift`), and nothing here reads the wall clock.    public static func calendarLines(_ now: Date, calendar: Calendar = .current) -> (month: String, day: String) {        (            month: CottonDate.formatter("MMM", calendar).string(from: now).uppercased(),            day: CottonDate.formatter("d", calendar).string(from: now)        )    }    /// The objects with no printable face — they are self-evident, and a word    /// stamped across them would be a caption on a photograph.    public static let wordless: Set<String> = [        "calls", "goals", "locations", "videos",        // Ahead's envelopes standing in their pockets are its face; the word sits under it.        "ahead",        // The top slip already carries pencil scribble (2026-09-30).        "thoughts",        // The tool box's lid carries its handle; the word sits under it.        "tools",        // The framed page already carries its own printed layout; the word sits under it.        "artifacts",        // The guest book's pages already carry its signatures (Spec 9.3).        "members",        // The headset's earpiece is round and small; the word sits under it.        "assistants",        // The rolodex's cards and its globe plate are its face; the word sits under it.        "domains",        // The card drawer's labels hold their own cards; the word sits under it.        "storage",        // The Settings panel carries adjustment knobs; the name sits under it.        "settings",        // The breaker's face is its lever; the word sits under it.        "outages",        // The coins say what they are; the word sits under them (6 Nov 2026,        // when the coins took the wallet's place).        "money",        // The camera's face is its lens; the word sits under it.        "camera",        // Pictures whose face is already full — postcards, a jar of slips, a        // meter dial, letters in a tray, a tabbed file; the word sits under each.        "stories", "memory", "ai_usage", "imports", "projects",        // A takeaway bag says what it is; the word sits under it.        "food",    ]    /// Where each object's name is printed on it, as `scale` places it.    public static func table(in scale: ThemeScale) -> [String: ToolPrint] { [        // The clipboard's printed header.        "todos": ToolPrint(            cx: ToolPrintKnobs.toolPrintTodosCx, cy: ToolPrintKnobs.toolPrintTodosCy,            w: ToolPrintKnobs.toolPrintTodosW, h: ToolPrintKnobs.toolPrintTodosH,            face: .type        ),        // The pad's day number; the month band is `calendarMonth`.        "calendar": ToolPrint(            cx: ToolPrintKnobs.toolPrintCalendarCx, cy: ToolPrintKnobs.toolPrintCalendarCy,            w: ToolPrintKnobs.toolPrintCalendarW, h: ToolPrintKnobs.toolPrintCalendarH,            face: .display        ),        // Written across the open page.        "notes": ToolPrint(            cx: ToolPrintKnobs.toolPrintNotesCx, cy: ToolPrintKnobs.toolPrintNotesCy,            w: ToolPrintKnobs.toolPrintNotesW, h: ToolPrintKnobs.toolPrintNotesH,            rotation: ToolPrintKnobs.toolPrintNotesRotation, face: .hand        ),        // The journal's cover, in the bottler's serif.        "journal": ToolPrint(            cx: ToolPrintKnobs.toolPrintJournalCx, cy: ToolPrintKnobs.toolPrintJournalCy,            w: ToolPrintKnobs.toolPrintJournalW, h: ToolPrintKnobs.toolPrintJournalH,            face: .cap, ink: .cream, transform: .upper        ),        "mood": ToolPrint(            cx: ToolPrintKnobs.toolPrintMoodCx, cy: ToolPrintKnobs.toolPrintMoodCy,            w: ToolPrintKnobs.toolPrintMoodW, h: ToolPrintKnobs.toolPrintMoodH,            face: .type        ),        "messages": ToolPrint(            cx: ToolPrintKnobs.toolPrintMessagesCx, cy: ToolPrintKnobs.toolPrintMessagesCy,            w: ToolPrintKnobs.toolPrintMessagesW, h: ToolPrintKnobs.toolPrintMessagesH,            rotation: ToolPrintKnobs.toolPrintMessagesRotation, face: .hand        ),        "email": ToolPrint(            cx: ToolPrintKnobs.toolPrintEmailCx, cy: ToolPrintKnobs.toolPrintEmailCy,            w: ToolPrintKnobs.toolPrintEmailW, h: ToolPrintKnobs.toolPrintEmailH,            face: .type        ),        // The rolodex's index tab.        "people": ToolPrint(            cx: ToolPrintKnobs.toolPrintPeopleCx, cy: ToolPrintKnobs.toolPrintPeopleCy,            w: ToolPrintKnobs.toolPrintPeopleW, h: ToolPrintKnobs.toolPrintPeopleH,            face: .type        ),        // The masthead.        "news": ToolPrint(            cx: ToolPrintKnobs.toolPrintNewsCx, cy: ToolPrintKnobs.toolPrintNewsCy,            w: ToolPrintKnobs.toolPrintNewsW, h: ToolPrintKnobs.toolPrintNewsH,            face: .display        ),        // The book's cover.        "reader": ToolPrint(            cx: ToolPrintKnobs.toolPrintReaderCx, cy: ToolPrintKnobs.toolPrintReaderCy,            w: ToolPrintKnobs.toolPrintReaderW, h: ToolPrintKnobs.toolPrintReaderH,            face: .display        ),        // The clock's dial, under the hands.        "alarms": ToolPrint(            cx: ToolPrintKnobs.toolPrintAlarmsCx, cy: ToolPrintKnobs.toolPrintAlarmsCy,            w: ToolPrintKnobs.toolPrintAlarmsW, h: ToolPrintKnobs.toolPrintAlarmsH,            face: .type        ),        "meetings": ToolPrint(            cx: ToolPrintKnobs.toolPrintMeetingsCx, cy: ToolPrintKnobs.toolPrintMeetingsCy,            w: ToolPrintKnobs.toolPrintMeetingsW, h: ToolPrintKnobs.toolPrintMeetingsH,            face: .type        ),        "documents": ToolPrint(            cx: ToolPrintKnobs.toolPrintDocumentsCx, cy: ToolPrintKnobs.toolPrintDocumentsCy,            w: ToolPrintKnobs.toolPrintDocumentsW, h: ToolPrintKnobs.toolPrintDocumentsH,            face: .type        ),        // Written in the print's white border.        "photos": ToolPrint(            cx: ToolPrintKnobs.toolPrintPhotosCx, cy: ToolPrintKnobs.toolPrintPhotosCy,            w: ToolPrintKnobs.toolPrintPhotosW, h: ToolPrintKnobs.toolPrintPhotosH,            face: .hand        ),        // The key's paper tag, hanging at its own angle.        "passwords": ToolPrint(            cx: ToolPrintKnobs.toolPrintPasswordsCx, cy: ToolPrintKnobs.toolPrintPasswordsCy,            w: ToolPrintKnobs.toolPrintPasswordsW, h: ToolPrintKnobs.toolPrintPasswordsH,            rotation: ToolPrintKnobs.toolPrintPasswordsRotation, face: .type        ),        // The printout's own cream band, under the run the top sheet carries.        "code": ToolPrint(            cx: ToolPrintKnobs.toolPrintCodeCx, cy: ToolPrintKnobs.toolPrintCodeCy,            w: ToolPrintKnobs.toolPrintCodeW, h: ToolPrintKnobs.toolPrintCodeH,            face: .type        ),        // The closed laptop's lid, lower right — the one blank face in the        // picture (the desktop machine's is louvred and the dock's is a        // connector), set at the lid's own slight lean.        "devices": ToolPrint(            cx: ToolPrintKnobs.toolPrintDevicesCx, cy: ToolPrintKnobs.toolPrintDevicesCy,            w: ToolPrintKnobs.toolPrintDevicesW, h: ToolPrintKnobs.toolPrintDevicesH,            rotation: ToolPrintKnobs.toolPrintDevicesRotation, face: .type        ),        // The bin's blank enamel label.        "bin": ToolPrint(            cx: ToolPrintKnobs.toolPrintBinCx, cy: ToolPrintKnobs.toolPrintBinCy,            w: ToolPrintKnobs.toolPrintBinW, h: ToolPrintKnobs.toolPrintBinH,            face: .type        ),        // The top ledger’s blank paper label.        "everything": ToolPrint(            cx: ToolPrintKnobs.toolPrintEverythingCx, cy: ToolPrintKnobs.toolPrintEverythingCy,            w: ToolPrintKnobs.toolPrintEverythingW, h: ToolPrintKnobs.toolPrintEverythingH,            face: .type        ),        // The suggestion box's cream label plate.        "feedback": ToolPrint(            cx: ToolPrintKnobs.toolPrintFeedbackCx, cy: ToolPrintKnobs.toolPrintFeedbackCy,            w: ToolPrintKnobs.toolPrintFeedbackW, h: ToolPrintKnobs.toolPrintFeedbackH,            face: .type        ),    ] }}/// The sizes, counts and timings ToolPrint draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enum ToolPrintKnobs {    static let toolPrintAlarmsCx: CGFloat = 0.5    static let toolPrintAlarmsCy: CGFloat = 0.7    static let toolPrintAlarmsH: CGFloat = 0.085    static let toolPrintAlarmsW: CGFloat = 0.36    static let toolPrintBinCx: CGFloat = 0.497    static let toolPrintBinCy: CGFloat = 0.615    static let toolPrintBinH: CGFloat = 0.1    static let toolPrintBinW: CGFloat = 0.36    static let toolPrintCalendarCx: CGFloat = 0.5    static let toolPrintCalendarCy: CGFloat = 0.6    static let toolPrintCalendarH: CGFloat = 0.28    static let toolPrintCalendarMonthCx: CGFloat = 0.5    static let toolPrintCalendarMonthCy: CGFloat = 0.36    static let toolPrintCalendarMonthH: CGFloat = 0.085    static let toolPrintCalendarMonthW: CGFloat = 0.4    static let toolPrintCalendarW: CGFloat = 0.5    static let toolPrintCodeCx: CGFloat = 0.5    static let toolPrintCodeCy: CGFloat = 0.6    static let toolPrintCodeH: CGFloat = 0.11    static let toolPrintCodeW: CGFloat = 0.46    static let toolPrintDevicesCx: CGFloat = 0.755    static let toolPrintDevicesCy: CGFloat = 0.62    static let toolPrintDevicesH: CGFloat = 0.055    static let toolPrintDevicesRotation: CGFloat = -2    static let toolPrintDevicesW: CGFloat = 0.235    static let toolPrintDocumentsCx: CGFloat = 0.5    static let toolPrintDocumentsCy: CGFloat = 0.55    static let toolPrintDocumentsH: CGFloat = 0.12    static let toolPrintDocumentsW: CGFloat = 0.58    static let toolPrintEmailCx: CGFloat = 0.5    static let toolPrintEmailCy: CGFloat = 0.56    static let toolPrintEmailH: CGFloat = 0.11    static let toolPrintEmailW: CGFloat = 0.52    static let toolPrintEverythingCx: CGFloat = 0.512    static let toolPrintEverythingCy: CGFloat = 0.29    static let toolPrintEverythingH: CGFloat = 0.11    static let toolPrintEverythingW: CGFloat = 0.32    static let toolPrintFeedbackCx: CGFloat = 0.492    static let toolPrintFeedbackCy: CGFloat = 0.655    static let toolPrintFeedbackH: CGFloat = 0.085    static let toolPrintFeedbackW: CGFloat = 0.34    static let toolPrintFontFraction: CGFloat = 0.8    static let toolPrintJournalCx: CGFloat = 0.5    static let toolPrintJournalCy: CGFloat = 0.5    static let toolPrintJournalH: CGFloat = 0.11    static let toolPrintJournalW: CGFloat = 0.5    static let toolPrintMeetingsCx: CGFloat = 0.5    static let toolPrintMeetingsCy: CGFloat = 0.335    static let toolPrintMeetingsH: CGFloat = 0.08    static let toolPrintMeetingsW: CGFloat = 0.48    static let toolPrintMessagesCx: CGFloat = 0.5    static let toolPrintMessagesCy: CGFloat = 0.7    static let toolPrintMessagesH: CGFloat = 0.12    static let toolPrintMessagesRotation: CGFloat = -3    static let toolPrintMessagesW: CGFloat = 0.58    static let toolPrintMoodCx: CGFloat = 0.5    static let toolPrintMoodCy: CGFloat = 0.77    static let toolPrintMoodH: CGFloat = 0.1    static let toolPrintMoodW: CGFloat = 0.44    static let toolPrintNewsCx: CGFloat = 0.5    static let toolPrintNewsCy: CGFloat = 0.29    static let toolPrintNewsH: CGFloat = 0.14    static let toolPrintNewsW: CGFloat = 0.7    static let toolPrintNotesCx: CGFloat = 0.5    static let toolPrintNotesCy: CGFloat = 0.48    static let toolPrintNotesH: CGFloat = 0.16    static let toolPrintNotesRotation: CGFloat = -3    static let toolPrintNotesW: CGFloat = 0.62    static let toolPrintPasswordsCx: CGFloat = 0.645    static let toolPrintPasswordsCy: CGFloat = 0.565    static let toolPrintPasswordsH: CGFloat = 0.085    static let toolPrintPasswordsRotation: CGFloat = -28    static let toolPrintPasswordsW: CGFloat = 0.25    static let toolPrintPeopleCx: CGFloat = 0.5    static let toolPrintPeopleCy: CGFloat = 0.575    static let toolPrintPeopleH: CGFloat = 0.09    static let toolPrintPeopleW: CGFloat = 0.34    static let toolPrintPhotosCx: CGFloat = 0.5    static let toolPrintPhotosCy: CGFloat = 0.84    static let toolPrintPhotosH: CGFloat = 0.09    static let toolPrintPhotosW: CGFloat = 0.44    static let toolPrintReaderCx: CGFloat = 0.5    static let toolPrintReaderCy: CGFloat = 0.6    static let toolPrintReaderH: CGFloat = 0.12    static let toolPrintReaderW: CGFloat = 0.52    static let toolPrintTodosCx: CGFloat = 0.5    static let toolPrintTodosCy: CGFloat = 0.38    static let toolPrintTodosH: CGFloat = 0.12    static let toolPrintTodosW: CGFloat = 0.54}