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