Commit 7cec273175
Verified · cmc
Changed files (6)
Sources/Orgstar/AgendaRowView.swift +14 −13 · view
| @@ -17,13 +17,14 @@ struct AgendaRowView: View { | ||
| 17 | 17 | /// Marked for a bulk action. |
| 18 | 18 | var marked = false |
| 19 | 19 | @Environment(\.orgTheme) private var theme |
| 20 | @ScaledMetric(relativeTo: .callout) private var gutterWidth = AgendaRowView.gutterWidth | |
| 20 | @Environment(\.textScale) private var scale | |
| 21 | 21 | @Environment(\.colorSchemeContrast) private var contrast |
| 22 | 22 | @Environment(\.accessibilityDifferentiateWithoutColor) private var withoutColor |
| 23 | @ScaledMetric(relativeTo: .caption) private var badgeSize: CGFloat = 18 | |
| 24 | 23 | |
| 25 | 24 | static let gutterWidth: CGFloat = 92 |
| 26 | 25 | |
| 26 | private var badgeSize: CGFloat { 18 * scale } | |
| 27 | ||
| 27 | 28 | var body: some View { |
| 28 | 29 | HStack(alignment: .top, spacing: 12) { |
| 29 | 30 | if showsGutter { gutter } |
| @@ -34,7 +35,7 @@ struct AgendaRowView: View { | ||
| 34 | 35 | marks |
| 35 | 36 | } |
| 36 | 37 | Text(row.title.isEmpty ? " " : row.title) |
| 37 | .font(.body) | |
| 38 | .font(.scaled(.body, scale)) | |
| 38 | 39 | .strikethrough(row.isDone) |
| 39 | 40 | .foregroundStyle(row.isDone ? AnyShapeStyle(.secondary) : AnyShapeStyle(theme.color("foreground") ?? .primary)) |
| 40 | 41 | .lineLimit(1) |
| @@ -76,21 +77,21 @@ struct AgendaRowView: View { | ||
| 76 | 77 | VStack(alignment: .leading, spacing: 2) { |
| 77 | 78 | let lines = row.gutterLines |
| 78 | 79 | Text(lines[0]) |
| 79 | .font(.callout.weight(row.status == .overdue || row.status == .dueSoon ? .semibold : .regular).monospacedDigit()) | |
| 80 | .font(.scaled(.callout, scale).weight(row.status == .overdue || row.status == .dueSoon ? .semibold : .regular).monospacedDigit()) | |
| 80 | 81 | .foregroundStyle(statusColor) |
| 81 | 82 | .lineLimit(2) |
| 82 | 83 | .fixedSize(horizontal: false, vertical: true) |
| 83 | 84 | if lines.count > 1 { |
| 84 | Text(lines[1]).font(.caption.monospacedDigit()).foregroundStyle(.secondary) | |
| 85 | Text(lines[1]).font(.scaled(.caption, scale).monospacedDigit()).foregroundStyle(.secondary) | |
| 85 | 86 | } |
| 86 | 87 | if let symbol = row.symbol { |
| 87 | 88 | Image(systemName: symbol) |
| 88 | .font(.caption.weight(.semibold)) | |
| 89 | .font(.scaled(.caption, scale).weight(.semibold)) | |
| 89 | 90 | .imageScale(row.icon == .event ? .small : .medium) |
| 90 | 91 | .foregroundStyle(iconColor) |
| 91 | 92 | } |
| 92 | 93 | } |
| 93 | .frame(width: gutterWidth, alignment: .leading) | |
| 94 | .frame(width: Self.gutterWidth * scale, alignment: .leading) | |
| 94 | 95 | } |
| 95 | 96 | |
| 96 | 97 | private var iconColor: Color { |
| @@ -108,21 +109,21 @@ struct AgendaRowView: View { | ||
| 108 | 109 | ?? theme.dynamic { [theme, row] in theme.categoryColor(row.category, dark: $0) }) |
| 109 | 110 | .frame(width: 6, height: 6) |
| 110 | 111 | Text(row.category) |
| 111 | .font(.subheadline) | |
| 112 | .font(.scaled(.subheadline, scale)) | |
| 112 | 113 | .foregroundStyle(theme.color("agenda-category") ?? .secondary) |
| 113 | 114 | .lineLimit(1) |
| 114 | 115 | } |
| 115 | 116 | } |
| 116 | 117 | if let detail = row.prefixDetail { |
| 117 | 118 | Text(detail) |
| 118 | .font(.subheadline) | |
| 119 | .font(.scaled(.subheadline, scale)) | |
| 119 | 120 | .foregroundStyle(.secondary) |
| 120 | 121 | .lineLimit(1) |
| 121 | 122 | .truncationMode(.middle) |
| 122 | 123 | } |
| 123 | 124 | ForEach([row.progress, row.detail].compactMap { $0 }, id: \.self) { progress in |
| 124 | 125 | Text(progress) |
| 125 | .font(.caption.weight(.semibold).monospacedDigit()) | |
| 126 | .font(.scaled(.caption, scale).weight(.semibold).monospacedDigit()) | |
| 126 | 127 | .foregroundStyle(.secondary) |
| 127 | 128 | .padding(.horizontal, 6) |
| 128 | 129 | .padding(.vertical, 1) |
| @@ -130,7 +131,7 @@ struct AgendaRowView: View { | ||
| 130 | 131 | } |
| 131 | 132 | ForEach(row.tags, id: \.self) { tag in |
| 132 | 133 | Text(tag) |
| 133 | .font(.caption.weight(.medium)) | |
| 134 | .font(.scaled(.caption, scale).weight(.medium)) | |
| 134 | 135 | .foregroundStyle(theme.color("tags") ?? .secondary) |
| 135 | 136 | .padding(.horizontal, 6) |
| 136 | 137 | .padding(.vertical, 1) |
| @@ -149,7 +150,7 @@ struct AgendaRowView: View { | ||
| 149 | 150 | if withoutColor, row.isDone { Image(systemName: "checkmark") } |
| 150 | 151 | Text(todo) |
| 151 | 152 | } |
| 152 | .font(.caption.weight(.bold)) | |
| 153 | .font(.scaled(.caption, scale).weight(.bold)) | |
| 153 | 154 | .foregroundStyle(highContrast ? background : color) |
| 154 | 155 | .padding(.horizontal, 7) |
| 155 | 156 | .padding(.vertical, 2) |
| @@ -166,7 +167,7 @@ struct AgendaRowView: View { | ||
| 166 | 167 | if let priority = row.priority { |
| 167 | 168 | let color = theme.dynamic(.systemOrange) { [theme] in theme.priorityColor(priority, dark: $0) } |
| 168 | 169 | Text(priority) |
| 169 | .font(.caption.weight(.bold)) | |
| 170 | .font(.scaled(.caption, scale).weight(.bold)) | |
| 170 | 171 | .foregroundStyle(highContrast ? background : color) |
| 171 | 172 | .frame(width: badgeSize, height: badgeSize) |
| 172 | 173 | .background(Circle().fill(highContrast ? color : color.opacity(0.14))) |
Sources/Orgstar/AgendaSidebar.swift +8 −6 · view
| @@ -24,6 +24,7 @@ struct AgendaSidebar: View { | ||
| 24 | 24 | @Environment(\.orgTheme) private var theme |
| 25 | 25 | @Environment(\.colorScheme) private var colorScheme |
| 26 | 26 | @Environment(\.openWindow) private var openWindow |
| 27 | @Environment(\.textScale) private var scale | |
| 27 | 28 | |
| 28 | 29 | init(workspace: WorkspaceModel, session: DocumentSession, commands: AppCommands, hour: Int, showsAgenda: Binding<Bool>) { |
| 29 | 30 | self.workspace = workspace |
| @@ -84,14 +85,14 @@ struct AgendaSidebar: View { | ||
| 84 | 85 | let groups = groups |
| 85 | 86 | List { |
| 86 | 87 | if groups.allSatisfy(\.rows.isEmpty) { |
| 87 | Text("Nothing scheduled").foregroundStyle(.secondary) | |
| 88 | Text("Nothing scheduled").font(.scaled(.body, scale)).foregroundStyle(.secondary) | |
| 88 | 89 | } |
| 89 | 90 | ForEach(groups) { group in |
| 90 | 91 | if !group.rows.isEmpty { |
| 91 | 92 | Section { |
| 92 | 93 | ForEach(Array(group.rows.enumerated()), id: \.offset) { _, row in line(row) } |
| 93 | 94 | } header: { |
| 94 | Text(group.header).foregroundStyle((group.isToday ? theme.color("agenda-today") : theme.color("sidebar-header")) ?? .secondary) | |
| 95 | Text(group.header).font(.scaled(.subheadline, scale).weight(.semibold)).foregroundStyle((group.isToday ? theme.color("agenda-today") : theme.color("sidebar-header")) ?? .secondary) | |
| 95 | 96 | } |
| 96 | 97 | } |
| 97 | 98 | } |
| @@ -122,10 +123,10 @@ struct AgendaSidebar: View { | ||
| 122 | 123 | let label = HStack(alignment: .firstTextBaseline, spacing: 6) { |
| 123 | 124 | if !row.gutter.isEmpty { |
| 124 | 125 | Text(row.gutter) |
| 125 | .font(.caption) | |
| 126 | .font(.scaled(.caption, scale)) | |
| 126 | 127 | .monospacedDigit() |
| 127 | 128 | .foregroundStyle(theme.dynamic(.secondaryLabelColor) { [theme] in theme.statusColor(row.status, dark: $0) }) |
| 128 | .frame(width: 52, alignment: .trailing) | |
| 129 | .frame(width: 52 * scale, alignment: .trailing) | |
| 129 | 130 | .lineLimit(1) |
| 130 | 131 | .minimumScaleFactor(0.7) |
| 131 | 132 | } |
| @@ -133,16 +134,17 @@ struct AgendaSidebar: View { | ||
| 133 | 134 | HStack(alignment: .firstTextBaseline, spacing: 4) { |
| 134 | 135 | if let todo = row.todo { |
| 135 | 136 | Text(todo) |
| 136 | .font(.caption.bold()) | |
| 137 | .font(.scaled(.caption, scale).bold()) | |
| 137 | 138 | .foregroundStyle(theme.dynamic(row.isDone ? .systemGreen : .systemRed) { [theme] in theme.todoColor(todo, isDone: row.isDone, dark: $0) }) |
| 138 | 139 | } |
| 139 | 140 | Text(row.title.isEmpty ? "(untitled)" : row.title) |
| 141 | .font(.scaled(.body, scale)) | |
| 140 | 142 | .lineLimit(2) |
| 141 | 143 | .strikethrough(row.isDone) |
| 142 | 144 | .foregroundStyle(row.isDone ? .secondary : theme.color("sidebar-foreground") ?? .primary) |
| 143 | 145 | } |
| 144 | 146 | if !row.category.isEmpty { |
| 145 | Text(row.category).font(.caption2).foregroundStyle(.secondary).lineLimit(1) | |
| 147 | Text(row.category).font(.scaled(.caption2, scale)).foregroundStyle(.secondary).lineLimit(1) | |
| 146 | 148 | } |
| 147 | 149 | } |
| 148 | 150 | } |
Sources/Orgstar/AgendaView.swift +14 −13 · view
| @@ -59,7 +59,8 @@ struct AgendaView: View { | ||
| 59 | 59 | @State var pickedDate = Date() |
| 60 | 60 | @AppStorage("agendaOverdueExpanded") private var overdueShown = true |
| 61 | 61 | @State private var hovered: String? |
| 62 | @ScaledMetric(relativeTo: .callout) private var gutterWidth = AgendaRowView.gutterWidth | |
| 62 | @Environment(\.textScale) private var scale | |
| 63 | private var gutterWidth: CGFloat { AgendaRowView.gutterWidth * scale } | |
| 63 | 64 | @FocusState private var focused: Bool |
| 64 | 65 | @AppStorage("agendaSpan") var span = 10 |
| 65 | 66 | @AppStorage("agendaStartOffset") var startOffset = 0 |
| @@ -297,7 +298,7 @@ struct AgendaView: View { | ||
| 297 | 298 | } |
| 298 | 299 | } |
| 299 | 300 | } header: { |
| 300 | header { Text(block.header).font(.body.weight(.semibold)) } | |
| 301 | header { Text(block.header).font(.scaled(.body, scale).weight(.semibold)) } | |
| 301 | 302 | } |
| 302 | 303 | } |
| 303 | 304 | } else if isAgenda { |
| @@ -314,7 +315,7 @@ struct AgendaView: View { | ||
| 314 | 315 | rowView(Line(id: "list:\(index)", row: row, day: agenda.today), showsGutter: false) |
| 315 | 316 | } |
| 316 | 317 | } header: { |
| 317 | header { Text(listTitle).font(.body.weight(.semibold)) } | |
| 318 | header { Text(listTitle).font(.scaled(.body, scale).weight(.semibold)) } | |
| 318 | 319 | } |
| 319 | 320 | } |
| 320 | 321 | } |
| @@ -338,7 +339,7 @@ struct AgendaView: View { | ||
| 338 | 339 | PromptBar(request: $prompt) |
| 339 | 340 | } else if let message = message ?? (filter.isEmpty ? reminderStatus : String(localized: "Filter: \(filter.description)")) { |
| 340 | 341 | Text(message) |
| 341 | .font(.callout) | |
| 342 | .font(.scaled(.callout, scale)) | |
| 342 | 343 | .frame(maxWidth: .infinity, alignment: .leading) |
| 343 | 344 | .padding(.horizontal, 12) |
| 344 | 345 | .padding(.vertical, 6) |
| @@ -423,7 +424,7 @@ struct AgendaView: View { | ||
| 423 | 424 | } |
| 424 | 425 | if group.isEmpty { |
| 425 | 426 | Text("Nothing scheduled") |
| 426 | .font(.callout) | |
| 427 | .font(.scaled(.callout, scale)) | |
| 427 | 428 | .foregroundStyle(.secondary) |
| 428 | 429 | .padding(.horizontal, 16) |
| 429 | 430 | .padding(.vertical, 10) |
| @@ -450,7 +451,7 @@ struct AgendaView: View { | ||
| 450 | 451 | private func gridLine(_ time: Int) -> some View { |
| 451 | 452 | HStack(spacing: 6) { |
| 452 | 453 | Text(String(format: "%02d:%02d", time / 100, time % 100)) |
| 453 | .font(.caption.monospacedDigit()) | |
| 454 | .font(.scaled(.caption, scale).monospacedDigit()) | |
| 454 | 455 | .frame(width: gutterWidth, alignment: .leading) |
| 455 | 456 | GridRule().stroke(style: StrokeStyle(lineWidth: 0.5, dash: [2, 3])).frame(height: 1) |
| 456 | 457 | } |
| @@ -475,19 +476,19 @@ struct AgendaView: View { | ||
| 475 | 476 | return header { |
| 476 | 477 | if let relative = group.relativeName(today: agenda.today) { |
| 477 | 478 | Text(relative) |
| 478 | .font(.body.weight(.bold)) | |
| 479 | .font(.scaled(.body, scale).weight(.bold)) | |
| 479 | 480 | .foregroundStyle(color) |
| 480 | 481 | Text("·").foregroundStyle(.tertiary) |
| 481 | 482 | } |
| 482 | 483 | Text(Self.format(group.day, Days.date(group.day).year == Days.date(agenda.today).year ? "EEEE d MMMM" : "EEEE d MMMM yyyy")) |
| 483 | .font(.body.weight(group.isToday ? .bold : .semibold)) | |
| 484 | .font(.scaled(.body, scale).weight(group.isToday ? .bold : .semibold)) | |
| 484 | 485 | .foregroundStyle(color) |
| 485 | 486 | Spacer() |
| 486 | 487 | Button { |
| 487 | 488 | capture(on: group.day) |
| 488 | 489 | } label: { |
| 489 | 490 | Image(systemName: "plus") |
| 490 | .font(.callout.weight(.semibold)) | |
| 491 | .font(.scaled(.callout, scale).weight(.semibold)) | |
| 491 | 492 | .frame(width: 22, height: 22) |
| 492 | 493 | .contentShape(Rectangle()) |
| 493 | 494 | } |
| @@ -505,11 +506,11 @@ struct AgendaView: View { | ||
| 505 | 506 | } label: { |
| 506 | 507 | HStack(spacing: 6) { |
| 507 | 508 | Image(systemName: "chevron.right") |
| 508 | .font(.caption.weight(.bold)) | |
| 509 | .font(.scaled(.caption, scale).weight(.bold)) | |
| 509 | 510 | .rotationEffect(.degrees(overdueShown ? 90 : 0)) |
| 510 | Text("Overdue").font(.callout.weight(.semibold)) | |
| 511 | Text("Overdue").font(.scaled(.callout, scale).weight(.semibold)) | |
| 511 | 512 | Text("\(count)") |
| 512 | .font(.caption.weight(.bold).monospacedDigit()) | |
| 513 | .font(.scaled(.caption, scale).weight(.bold).monospacedDigit()) | |
| 513 | 514 | .padding(.horizontal, 6) |
| 514 | 515 | .padding(.vertical, 1) |
| 515 | 516 | .background(Capsule().fill(color.opacity(0.15))) |
| @@ -528,7 +529,7 @@ struct AgendaView: View { | ||
| 528 | 529 | private var nowLine: some View { |
| 529 | 530 | HStack(spacing: 6) { |
| 530 | 531 | Text(now.formatted(.dateTime.hour(.twoDigits(amPM: .omitted)).minute())) |
| 531 | .font(.caption.weight(.semibold).monospacedDigit()) | |
| 532 | .font(.scaled(.caption, scale).weight(.semibold).monospacedDigit()) | |
| 532 | 533 | .frame(width: gutterWidth, alignment: .leading) |
| 533 | 534 | Circle().frame(width: 6, height: 6) |
| 534 | 535 | Rectangle().frame(height: 1) |
Sources/Orgstar/OrgstarApp.swift +2 · view
| @@ -546,6 +546,7 @@ struct OrgstarApp: App { | ||
| 546 | 546 | case .success(let model): |
| 547 | 547 | ContentView(workspace: model, session: session, commands: commands, scheduler: scheduler, clock: clock) |
| 548 | 548 | .environment(\.orgTheme, ConfigSync.shared.theme) |
| 549 | .textScaled() | |
| 549 | 550 | .tint(ConfigSync.shared.theme.color("accent")) |
| 550 | 551 | .onAppear { |
| 551 | 552 | delegate.session = session |
| @@ -577,6 +578,7 @@ struct OrgstarApp: App { | ||
| 577 | 578 | if case .success(let model) = workspace { |
| 578 | 579 | AgendaView(workspace: model, session: session, commands: commands, scheduler: scheduler, clock: clock) |
| 579 | 580 | .environment(\.orgTheme, ConfigSync.shared.theme) |
| 581 | .textScaled() | |
| 580 | 582 | .tint(ConfigSync.shared.theme.color("accent")) |
| 581 | 583 | } |
| 582 | 584 | } |
Sources/Orgstar/Sidebar.swift +6 −2 · view
| @@ -20,6 +20,7 @@ struct Sidebar: View { | ||
| 20 | 20 | /// A file operation waiting for a name or a confirmation. |
| 21 | 21 | @Environment(\.orgTheme) private var theme |
| 22 | 22 | @Environment(\.colorScheme) private var colorScheme |
| 23 | @Environment(\.textScale) private var scale | |
| 23 | 24 | @State var pending: FileOperation? |
| 24 | 25 | @State var name = "" |
| 25 | 26 | @State var failure: String? |
| @@ -41,7 +42,7 @@ struct Sidebar: View { | ||
| 41 | 42 | ForEach(workspace.rootPaths, id: \.self) { root in |
| 42 | 43 | Section(isExpanded: expanded(root)) { |
| 43 | 44 | OutlineGroup(workspace.tree(forRoot: root).children ?? [], children: \.children) { node in |
| 44 | Label(node.name, systemImage: icon(node)) | |
| 45 | Label { Text(node.name).font(.scaled(.body, scale)) } icon: { Image(systemName: icon(node)) } | |
| 45 | 46 | .foregroundStyle(node.file?.kind == .conflict ? .orange : node.isDownloading ? .secondary : theme.color("sidebar-foreground") ?? .primary) |
| 46 | 47 | .help(node.isDownloading ? "Downloading from iCloud" : "") |
| 47 | 48 | .tag(node.file?.path) |
| @@ -49,6 +50,7 @@ struct Sidebar: View { | ||
| 49 | 50 | } |
| 50 | 51 | } header: { |
| 51 | 52 | Text((root as NSString).lastPathComponent) |
| 53 | .font(.scaled(.subheadline, scale).weight(.semibold)) | |
| 52 | 54 | .foregroundStyle(theme.color("sidebar-header") ?? .secondary) |
| 53 | 55 | .help(root) |
| 54 | 56 | .contextMenu { folderMenu(root) } |
| @@ -193,6 +195,7 @@ struct SidebarBar<Content: View>: View { | ||
| 193 | 195 | struct OutlineColumn: View { |
| 194 | 196 | let session: DocumentSession |
| 195 | 197 | @Environment(\.orgTheme) private var theme |
| 198 | @Environment(\.textScale) private var scale | |
| 196 | 199 | @Environment(\.colorScheme) private var colorScheme |
| 197 | 200 | |
| 198 | 201 | var body: some View { |
| @@ -201,9 +204,10 @@ struct OutlineColumn: View { | ||
| 201 | 204 | session.reveal(entry.start) |
| 202 | 205 | } label: { |
| 203 | 206 | Text(entry.title.isEmpty ? "(untitled)" : entry.title) |
| 207 | .font(.scaled(.body, scale)) | |
| 204 | 208 | .foregroundStyle(theme.color("sidebar-foreground") ?? .primary) |
| 205 | 209 | .lineLimit(1) |
| 206 | .padding(.leading, CGFloat(entry.level - 1) * 12) | |
| 210 | .padding(.leading, CGFloat(entry.level - 1) * 12 * scale) | |
| 207 | 211 | } |
| 208 | 212 | .buttonStyle(.plain) |
| 209 | 213 | } |
Sources/Orgstar/TextScale.swift added +47 · view
| @@ -0,0 +1,47 @@ | ||
| 1 | import AppKit | |
| 2 | import OrgPresentation | |
| 3 | import SwiftUI | |
| 4 | ||
| 5 | extension EnvironmentValues { | |
| 6 | /// Settings ▸ Appearance ▸ Size over its default, never below 1: how much larger than the | |
| 7 | /// system's sizes the agenda and sidebars show text. macOS has no Dynamic Type to do this. | |
| 8 | @Entry var textScale: CGFloat = 1 | |
| 9 | } | |
| 10 | ||
| 11 | extension Font { | |
| 12 | /// `style` at the system's size for it times `scale`. | |
| 13 | static func scaled(_ style: Font.TextStyle, _ scale: CGFloat) -> Font { | |
| 14 | .system(size: NSFont.preferredFont(forTextStyle: style.appKit).pointSize * scale) | |
| 15 | } | |
| 16 | } | |
| 17 | ||
| 18 | extension Font.TextStyle { | |
| 19 | fileprivate var appKit: NSFont.TextStyle { | |
| 20 | switch self { | |
| 21 | case .largeTitle: .largeTitle | |
| 22 | case .title: .title1 | |
| 23 | case .title2: .title2 | |
| 24 | case .title3: .title3 | |
| 25 | case .headline: .headline | |
| 26 | case .subheadline: .subheadline | |
| 27 | case .callout: .callout | |
| 28 | case .footnote: .footnote | |
| 29 | case .caption: .caption1 | |
| 30 | case .caption2: .caption2 | |
| 31 | default: .body | |
| 32 | } | |
| 33 | } | |
| 34 | } | |
| 35 | ||
| 36 | private struct TextScaled: ViewModifier { | |
| 37 | @AppStorage("themeFontSize") private var size = ThemeSpec.default.fontSize | |
| 38 | ||
| 39 | func body(content: Content) -> some View { | |
| 40 | content.environment(\.textScale, max(1, CGFloat(size) / CGFloat(ThemeSpec.default.fontSize))) | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | extension View { | |
| 45 | /// Sets `textScale` from Settings ▸ Appearance ▸ Size. | |
| 46 | func textScaled() -> some View { modifier(TextScaled()) } | |
| 47 | } | |