// A list's row of links to other lists (`ListLink`), each its name and how// many it holds, and the few sizes the field lines beside it are drawn with.importSwiftUI/// A row of links to other lists, each its name and how many it holds/// ("Scenes 12 Lines 2"): a list's own list links (`ListLink`), on one line/// that scrolls sideways when they do not fit. Nothing for no link.structSideLinksRow: View { @Environment(\.theme) privatevar themelet links: [PageSideLink]/// Each link is identified "<identifier>-<link id>".let identifier: String/// The links are still being counted: with none to draw yet, the row/// keeps one link's height, so what stands under it does not move when/// they land.var holding = false/// Which edges links lie past, read off the scroll view's own geometry. @State privatevar edges = SideLinksEdges()var body: someView {if !links.isEmpty {// ONE row: links that do not fit the width scroll sideways on// their line, never wrap to a second (walk 1, shot 408 —// "Statements 179" fell under the others).ScrollViewReader { proxy inScrollView(.horizontal, showsIndicators: false) { HStack(spacing: FieldLineKnobs.wrapGap) {ForEach(links) { link inPaperTypedButton(link.words, size: FieldLineKnobs.linkButtonSize, action: link.open) .accessibilityIdentifier("\(identifier)-\(link.id)") .id(link.id) } } }// The scroll view's own geometry — its offset, its content's// width and its own — says which edge links lie past; a frame// measured inside the content by a preference never reached// the row (the fade did not show, walk 5 Oct). .modifier(SideLinksEdgesReading(edges: $edges)) .scrollBounceBehavior(.basedOnSize, axes: .horizontal)// A row with more links than fit SAYS so: the edge they run// off fades out, so "Drafts 2" past the card's edge is not a// link nobody knows is there (walk 5 Oct). .mask(SideLinksFade(more: (edges.before, edges.after)))// Back on the screen, the row starts at its first link, never// where it was left scrolled (a stray count at the edge). .onAppear { iflet first = links.first?.id { proxy.scrollTo(first, anchor: .leading) } } } } elseif holding {PaperTypedButton(" ", size: FieldLineKnobs.linkButtonSize) {} .hidden() .accessibilityHidden(true) } }/// Which edges of the row have links lying past them: `links` is the/// links' frame in the row's own space (it starts at 0 and moves left as/// the row is scrolled), `row` the width the row has.staticfunc more(links: CGRect, row: CGFloat) -> (before: Bool, after: Bool) {guard row > 0, links.width > row + 1else { return (false, false) }return (links.minX < -1, links.maxX > row + 1) }}/// Which edges of a row of links have links lying past them.structSideLinksEdges: Equatable {var before = falsevar after = false}/// Reads `SideLinksEdges` off the row's scroll geometry: the links' frame/// starts at minus the offset and is as wide as the content.privatestructSideLinksEdgesReading: ViewModifier { @Binding var edges: SideLinksEdgesfunc body(content: Content) -> someView {if #available(iOS 18, macOS 15, *) { content.onScrollGeometryChange(for: SideLinksEdges.self) { geometry inlet more = SideLinksRow.more( links: CGRect(x: -geometry.contentOffset.x, y: 0, width: geometry.contentSize.width, height: 0), row: geometry.containerSize.width)returnSideLinksEdges(before: more.before, after: more.after) } action: { _, now in edges = now } } else { content } }}/// The row's mask: opaque across it, fading to clear over the last stretch/// of an edge that links run past.privatestructSideLinksFade: View { @Environment(\.theme) privatevar themelet more: (before: Bool, after: Bool)privatevar reach: CGFloat { FieldLineKnobs.sideLinksFadeReach }var body: someView { HStack(spacing: 0) {LinearGradient(colors: [.black.opacity(more.before ? 0 : 1), .black], startPoint: .leading, endPoint: .trailing) .frame(width: reach) theme.colors.shadow.colorLinearGradient(colors: [.black, .black.opacity(more.after ? 0 : 1)], startPoint: .leading, endPoint: .trailing) .frame(width: reach) } .animation(.easeOut(duration: 0.15), value: more.before) .animation(.easeOut(duration: 0.15), value: more.after) }}/// One link of a row of links: a list by its label and how many records it/// holds ("Scenes 12").structPageSideLink: Identifiable {let id: Stringlet label: String/// How many records the list holds; nil before it is read. None is not/// counted: the link reads as its name alone.var count: Int?/// The definition's words for the count ("1 recording did not work"),/// when it has them; else the count stands beside the label.var units: ColumnUnits? = nilletopen: () -> Void @MainActorvar words: String {guardlet count, count > 0else { return label }return counted ?? CountLines.shared.line("lists", "link.side", n: count, fills: ["label": label]) ?? label }/// The count in the definition's own words, when it has them, as the/// core says it. @MainActorvar counted: String? {guardlet count, count > 0, let units else { returnnil }returnCountLines.shared.units(units, n: count) }}/// The sizes a field's line (a link's value, a web address), a slip's check/// and a row of links are drawn with: Swift's own, beside their readers — a/// theme sets only its tokens (`scale.tokens`).enumFieldLineKnobs {staticlet fieldLabelWidth: CGFloat = 96staticlet inlineGap: CGFloat = 12staticlet linkButtonSize: CGFloat = 15staticlet sideLinksFadeReach: CGFloat = 36staticlet wrapGap: CGFloat = 16staticlet slipCheckSide: CGFloat = 20}