Commit 0504a49cf7
Verified · cmc
Layout: unified · split
Sources/OrgstarMobile/SettingsScreen.swift +21 −1
| @@ -89,6 +89,19 @@ struct SettingsScreen: View { | ||
| 89 | 89 | } footer: { |
| 90 | 90 | if badges == false { Text("Turn on Badges in orgstar's notification settings.") } |
| 91 | 91 | } |
| 92 | Section("Appearance") { | |
| 93 | let _ = model.settingsVersion | |
| 94 | NavigationLink { | |
| 95 | ThemePickerScreen(model: model, appearance: .light) | |
| 96 | } label: { | |
| 97 | LabeledContent("Light Theme", value: ThemePickerScreen.current(.light).name) | |
| 98 | } | |
| 99 | NavigationLink { | |
| 100 | ThemePickerScreen(model: model, appearance: .dark) | |
| 101 | } label: { | |
| 102 | LabeledContent("Dark Theme", value: ThemePickerScreen.current(.dark).name) | |
| 103 | } | |
| 104 | } | |
| 92 | 105 | calendarSection |
| 93 | 106 | reminderSection |
| 94 | 107 | Section("In use") { |
| @@ -97,7 +110,7 @@ struct SettingsScreen: View { | ||
| 97 | 110 | LabeledContent("Agenda", value: agenda) |
| 98 | 111 | LabeledContent("Reminders", value: OrgPreferences.reminders() ? "\(OrgPreferences.reminderLead()) min before" : "Off") |
| 99 | 112 | LabeledContent("Capture templates", value: CaptureTemplates.load().templates.map(\.key).joined(separator: " ")) |
| 100 | LabeledContent("Theme", value: UserDefaults.standard.string(forKey: "themeFile").flatMap { $0.isEmpty ? nil : $0 } ?? "Default") | |
| 113 | LabeledContent("Theme", value: themeInUse) | |
| 101 | 114 | LabeledContent("Font", value: font) |
| 102 | 115 | } |
| 103 | 116 | } |
| @@ -110,6 +123,13 @@ struct SettingsScreen: View { | ||
| 110 | 123 | } |
| 111 | 124 | |
| 112 | 125 | /// `calendar-events` and `calendar-event-calendars`, written to config.toml. |
| 126 | /// The two palettes' names, and the theme file's when there is one. | |
| 127 | private var themeInUse: String { | |
| 128 | let names = "\(ThemePickerScreen.current(.light).name) / \(ThemePickerScreen.current(.dark).name)" | |
| 129 | guard let file = UserDefaults.standard.string(forKey: "themeFile"), !file.isEmpty else { return names } | |
| 130 | return "\(names), \(file)" | |
| 131 | } | |
| 132 | ||
| 113 | 133 | private var calendarSection: some View { |
| 114 | 134 | let _ = model.settingsVersion |
| 115 | 135 | let on = OrgPreferences.calendarEvents() |
Sources/OrgstarMobile/ThemePickerScreen.swift added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | #if os(iOS) | |
| 2 | import OrgCore | |
| 3 | import OrgPresentation | |
| 4 | import SwiftUI | |
| 5 | ||
| 6 | /// The built-in palettes of one appearance, each as a few lines of Org in its colors. | |
| 7 | struct ThemePickerScreen: View { | |
| 8 | let model: MobileModel | |
| 9 | let appearance: Palette.Appearance | |
| 10 | ||
| 11 | var body: some View { | |
| 12 | let _ = model.settingsVersion | |
| 13 | let current = Self.current(appearance).id | |
| 14 | List(ThemeSpec.palettes(appearance), id: \.id) { palette in | |
| 15 | Button { | |
| 16 | model.set(appearance == .light ? "themeLight" : "themeDark", to: .string(palette.id)) | |
| 17 | } label: { | |
| 18 | HStack { | |
| 19 | VStack(alignment: .leading, spacing: 6) { | |
| 20 | Text(palette.name).foregroundStyle(.primary) | |
| 21 | Self.sample(palette) | |
| 22 | } | |
| 23 | Spacer() | |
| 24 | if palette.id == current { Image(systemName: "checkmark").foregroundStyle(.tint) } | |
| 25 | } | |
| 26 | } | |
| 27 | } | |
| 28 | .navigationTitle(appearance == .light ? "Light Theme" : "Dark Theme") | |
| 29 | } | |
| 30 | ||
| 31 | /// The palette `light-theme` or `dark-theme` names, Default when unknown. | |
| 32 | static func current(_ appearance: Palette.Appearance) -> Palette { | |
| 33 | let id = UserDefaults.standard.string(forKey: appearance == .light ? "themeLight" : "themeDark") ?? "" | |
| 34 | return ThemeSpec.palette(id, appearance) ?? ThemeSpec.palettes(appearance)[0] | |
| 35 | } | |
| 36 | ||
| 37 | private static func sample(_ palette: Palette) -> some View { | |
| 38 | func color(_ key: String) -> Color { | |
| 39 | guard let c = palette.colors[key] else { return .primary } | |
| 40 | return Color(.sRGB, red: c.red, green: c.green, blue: c.blue, opacity: c.alpha) | |
| 41 | } | |
| 42 | let font = Font.system(.footnote, design: .monospaced) | |
| 43 | return VStack(alignment: .leading, spacing: 2) { | |
| 44 | (Text("* ").foregroundColor(color("heading-1")) + Text("TODO ").foregroundColor(color("todo")).bold() | |
| 45 | + Text("Plan the trip ").foregroundColor(color("heading-1")).bold() + Text(":travel:").foregroundColor(color("tags"))) | |
| 46 | (Text(" SCHEDULED: ").foregroundColor(color("metadata")) + Text("<2026-10-20 Tue>").foregroundColor(color("timestamp"))) | |
| 47 | (Text(" Book via ").foregroundColor(color("foreground")) + Text("the site").foregroundColor(color("link")).underline() | |
| 48 | + Text(", ").foregroundColor(color("foreground")) + Text("~code~").foregroundColor(color("code"))) | |
| 49 | (Text("** ").foregroundColor(color("heading-2")) + Text("DONE ").foregroundColor(color("done")).bold() | |
| 50 | + Text("Passport").foregroundColor(color("heading-2")).bold()) | |
| 51 | } | |
| 52 | .font(font) | |
| 53 | .padding(8) | |
| 54 | .frame(maxWidth: .infinity, alignment: .leading) | |
| 55 | .background(color("background"), in: RoundedRectangle(cornerRadius: 8)) | |
| 56 | } | |
| 57 | } | |
| 58 | #endif | |