// The project scope, as the list column's paper shows it. // // Mac redesign spec ยง4. While the sidebar narrows the content to one or more // projects, the list column's screen says so: a row of the chosen projects' // caps under its title (`PaperScreen`), and an empty list that says what it is // empty OF (`ObjectEmpty`). Both read it from the environment โ€” the host sets // it on the list column, the phone never does, and neither component knows or // asks which platform it is on (`ScreenPlatformSweepTests`). import SwiftUI /// One chosen project, as a chip draws it. public struct ScopeChip: Equatable, Identifiable, Sendable { public let slug: String public let name: String public let colour: CapColour public var id: String { slug } public init(slug: String, name: String, colour: CapColour) { self.slug = slug self.name = name self.colour = colour } } public enum ScopeWording { /// An empty list under a scope: what it is empty of. One project by name, /// two by both names, more as "these projects" โ€” a sentence that lists /// five names is a sentence nobody reads to the end. public static func nothingIn(_ names: [String]) -> String? { switch names.count { case 0: return nil case 1: return ShellLines.line("empty", "scope.one", ["name": names[0]]) case 2: return ShellLines.line("empty", "scope.two", ["first": names[0], "second": names[1]]) default: return ShellLines.line("empty", "scope.many") } } } private struct CottonProjectScopeKey: EnvironmentKey { /// Empty, and empty is every project โ€” the phone, always. static let defaultValue: [ScopeChip] = [] } extension EnvironmentValues { /// The projects the content is narrowed to, in the sidebar's order; empty /// is every project. /// /// **Paper reads this; no screen does.** The list column's host sets it, /// and `PaperScreen` and `ObjectEmpty` draw it, so a screen shows its /// scope without a line of its own. public var cottonProjectScope: [ScopeChip] { get { self[CottonProjectScopeKey.self] } set { self[CottonProjectScopeKey.self] = newValue } } } /// The row of chosen caps, each with its name. struct ScopeChipRow: View { let chips: [ScopeChip] @Environment(\.theme) private var theme var body: some View { HStack(spacing: 12) { ForEach(chips) { chip in HStack(spacing: 5) { CapChip(name: chip.name, colour: chip.colour, side: 18) Text(chip.name) .font(CottonFonts.type(theme.scale.metaSize)) .foregroundStyle(CottonColors.inkSecondary) .lineLimit(1) } } } .accessibilityElement(children: .combine) .accessibilityIdentifier("paper-project-scope") } }