// What every tile face is drawn at and with: its size, its measurements, its // heading on the plaster and the slip it shows when it has nothing to draw. // // A tile is a table's face at a fixed size (`BoardTile`, `SlipTileFace`), drawn // on a board and on a database page's section. Every face is a fixed-size // drawing, like the paper voices: print on an object scales with the object, // never with Dynamic Type. import SwiftUI /// The three sizes a tile comes in, each a fixed canvas. public enum TileSize: String, Sendable, CaseIterable { case small, medium, large /// The tile's canvas on a 393-point phone. public var canvas: CGSize { switch self { case .small: return CGSize(width: 158, height: 158) case .medium: return CGSize(width: 338, height: 158) case .large: return CGSize(width: 338, height: 354) } } } /// The tile faces' shared measurements. public enum TileMetrics { /// The air every face keeps from its tile's edge: paper needs the room, /// and a sheet whose shadow is clipped by a margin reads as a sticker. public static let padding: CGFloat = 12 /// The gap between objects on a face. public static let gap: CGFloat = 10 /// A face's own heading on the plaster. public static let titleSize: CGFloat = 20 /// A handwritten note on the plaster — a count, the weather, "tomorrow". public static let noteSize: CGFloat = 15 /// The side of each of `columns` × `rows` objects of `aspect` (width ÷ /// height) laid with `gap` into `space` — the largest that fits BOTH ways. public static func side( fitting space: CGSize, columns: Int, rows: Int, aspect: CGFloat, gap: CGFloat = gap ) -> CGFloat { guard columns > 0, rows > 0, aspect > 0 else { return 0 } let across = (space.width - gap * CGFloat(columns - 1)) / CGFloat(columns) let down = (space.height - gap * CGFloat(rows - 1)) / CGFloat(rows) * aspect return max(0, min(across, down)) } } /// A face's heading, set on the plaster: the serif title and a handwritten note /// beside it. Ink on plaster is not multiplied — plaster is not paper. struct TileHeading: View { @Environment(\.theme) private var theme let title: String var note: String? var noteInk: PaperInk = .pencil var trailing: String? var body: some View { HStack(alignment: .firstTextBaseline, spacing: 8) { Text(title) .font(theme.type.title(TileMetrics.titleSize)) .foregroundStyle(theme.print(.ink)) .lineLimit(1) .layoutPriority(1) if let note { Text(note) .font(theme.type.hand(TileMetrics.noteSize)) .foregroundStyle(theme.print(noteInk)) .lineLimit(1) } Spacer(minLength: 4) if let trailing { Text(trailing) .font(theme.type.hand(TileMetrics.noteSize)) .foregroundStyle(theme.print(.pencil)) .lineLimit(1) } } } } /// What a face shows when it has nothing to draw: one torn slip with the /// sentence typed on it — the empty object, at tile size. public struct TileQuietSlip: View { private let line: String public init(line: String) { self.line = line } public var body: some View { // The seed is the torn edge's: it keeps the spelling every quiet slip // has always been drawn with, so the edge does not move. Paper(dye: .cream, edge: .torn, seed: "widget-quiet-\(line)") { Text(line) .paperBody(12.5, ink: .pencil) .lineLimit(3) .multilineTextAlignment(.leading) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity, alignment: .leading) } } }