aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Preferences
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-07-07 16:52:28 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-07-07 16:52:28 +0200
commite59dcf2bcf7841ebe6f3d85ec3ec03319b261da4 (patch)
tree3311ea9e5fbc9f26fe1b170318c9b179faf42dff /Map/Presentation/Preferences
parent3bacbf6ac85330d35493953d7296e5ba420b7750 (diff)
More localization keys, font editor preferences, better new file
Diffstat (limited to 'Map/Presentation/Preferences')
-rw-r--r--Map/Presentation/Preferences/AppearancePreferencesView.swift36
-rw-r--r--Map/Presentation/Preferences/EditorPreferencesView.swift120
-rw-r--r--Map/Presentation/Preferences/MapPreferencesView.swift23
3 files changed, 125 insertions, 54 deletions
diff --git a/Map/Presentation/Preferences/AppearancePreferencesView.swift b/Map/Presentation/Preferences/AppearancePreferencesView.swift
deleted file mode 100644
index a71276d..0000000
--- a/Map/Presentation/Preferences/AppearancePreferencesView.swift
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2024 Rubén Beltrán del Río
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see https://map.tranquil.systems.
-
-import SwiftUI
-
-struct AppearancePreferencesView: View {
- var body: some View {
- VStack {
- Text("Appearance Preferences")
- .font(.largeTitle)
- .padding()
-
- Text("Appearance settings will be available here in a future version.")
- .foregroundColor(.secondary)
-
- Spacer()
- }
- .padding()
- }
-}
-
-#Preview {
- AppearancePreferencesView()
-}
diff --git a/Map/Presentation/Preferences/EditorPreferencesView.swift b/Map/Presentation/Preferences/EditorPreferencesView.swift
new file mode 100644
index 0000000..3d456c9
--- /dev/null
+++ b/Map/Presentation/Preferences/EditorPreferencesView.swift
@@ -0,0 +1,120 @@
+// Copyright (C) 2024 Rubén Beltrán del Río
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see https://map.tranquil.systems.
+
+import SwiftUI
+
+struct EditorPreferencesView: View {
+
+ @AppStorage("useSmartEditor") private var useSmartEditor = false
+ @AppStorage("useCustomEditorFont") private var useCustomEditorFont = false
+ @AppStorage("customEditorFontName") private var customEditorFontName = "Menlo"
+ @AppStorage("editorFontSize") private var editorFontSize: Double = 14
+
+ var monospacedFonts: [String] {
+ let fontManager = NSFontManager.shared
+ let monospaceTrait = NSFontTraitMask.fixedPitchFontMask
+
+ return fontManager.availableFontFamilies.filter { familyName in
+ let members = fontManager.availableMembers(ofFontFamily: familyName) ?? []
+ return members.contains { member in
+ if let traits = member[3] as? NSNumber {
+ return NSFontTraitMask(rawValue: traits.uintValue).contains(monospaceTrait)
+ }
+ return false
+ }
+ }
+ }
+
+ var body: some View {
+ VStack(alignment: .center, spacing: Dimensions.Spacing.loose) {
+ HStack(alignment: .center, spacing: Dimensions.Spacing.regular) {
+ Button(action: {
+ if editorFontSize > 7 {
+ editorFontSize -= 1
+ }
+ }) {
+ Image(systemName: "textformat.size.smaller")
+ }
+ .buttonStyle(BorderlessButtonStyle())
+ .disabled(editorFontSize <= 7)
+ .help("preferences.editor.font_size.decrease.help")
+
+ Slider(value: $editorFontSize, in: 7...21, step: 1)
+ .frame(width: 250)
+
+ Button(action: {
+ if editorFontSize < 21 {
+ editorFontSize += 1
+ }
+ }) {
+ Image(systemName: "textformat.size.larger")
+ }
+ .buttonStyle(BorderlessButtonStyle())
+ .disabled(editorFontSize >= 21)
+ .help("preferences.editor.font_size.increase.help")
+ }
+
+ Divider()
+
+ HStack(alignment: .firstTextBaseline, spacing: Dimensions.Spacing.regular) {
+ Text("preferences.editor.editor_style.title")
+ .font(.Theme.Body.emphasized)
+ .frame(maxWidth: 250, alignment: .trailing)
+
+ VStack(alignment: .leading, spacing: Dimensions.Spacing.cozy) {
+
+ Toggle(
+ isOn: $useCustomEditorFont,
+ label: {
+ Text("preferences.editor.editor_style.use_custom_font")
+ .font(.Theme.Body.regular)
+ })
+
+ Picker("", selection: $customEditorFontName) {
+ ForEach(monospacedFonts, id: \.self) { fontFamily in
+ Text(fontFamily).tag(fontFamily)
+ }
+ }
+ .pickerStyle(MenuPickerStyle())
+ .frame(maxWidth: 250)
+ .padding(.leading, -Dimensions.Spacing.regular)
+ .disabled(!useCustomEditorFont)
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+
+ Divider()
+
+ HStack(alignment: .firstTextBaseline, spacing: Dimensions.Spacing.regular) {
+ Text("preferences.editor.smart_editor.title")
+ .font(.Theme.Body.emphasized)
+ .frame(maxWidth: 250, alignment: .trailing)
+
+ VStack(alignment: .leading, spacing: Dimensions.Spacing.cozy) {
+ Toggle(
+ String(localized: "preferences.editor.smart_editor.enabled"), isOn: $useSmartEditor)
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+
+ Spacer()
+ }.padding(.vertical, Dimensions.Spacing.loose)
+ .padding(.horizontal, Dimensions.Spacing.indulgent)
+ }
+}
+
+#Preview {
+ EditorPreferencesView()
+}
diff --git a/Map/Presentation/Preferences/MapPreferencesView.swift b/Map/Presentation/Preferences/MapPreferencesView.swift
index 264be14..d81916f 100644
--- a/Map/Presentation/Preferences/MapPreferencesView.swift
+++ b/Map/Presentation/Preferences/MapPreferencesView.swift
@@ -17,7 +17,6 @@ import SwiftUI
struct MapPreferencesView: View {
@AppStorage("showMapBackground") private var showBackground = true
- @AppStorage("useSmartEditor") private var useSmartEditor = false
@AppStorage("useCustomFont") private var useCustomFont = false
@AppStorage("customFontName") private var customFontName = "Helvetica"
@@ -26,7 +25,7 @@ struct MapPreferencesView: View {
HStack(alignment: .firstTextBaseline, spacing: Dimensions.Spacing.regular) {
Text("preferences.map.map_style.title")
.font(.Theme.Body.emphasized)
- .frame(maxWidth: .infinity, alignment: .trailing)
+ .frame(maxWidth: 250, alignment: .trailing)
VStack(alignment: .leading, spacing: Dimensions.Spacing.cozy) {
Toggle(
@@ -49,28 +48,16 @@ struct MapPreferencesView: View {
}
}
.pickerStyle(MenuPickerStyle())
+ .frame(maxWidth: 250)
+ .padding(.leading, -Dimensions.Spacing.regular)
.disabled(!useCustomFont)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
- Divider()
-
- HStack(alignment: .firstTextBaseline, spacing: Dimensions.Spacing.regular) {
- Text("preferences.map.editor.title")
- .font(.Theme.Body.emphasized)
- .frame(maxWidth: .infinity, alignment: .trailing)
-
- VStack(alignment: .leading, spacing: Dimensions.Spacing.cozy) {
- Toggle(
- String(localized: "preferences.map.editor.use_smart_editor"), isOn: $useSmartEditor)
- }
- .frame(maxWidth: .infinity, alignment: .leading)
- }
-
Spacer()
- }
- .padding()
+ }.padding(.vertical, Dimensions.Spacing.loose)
+ .padding(.horizontal, Dimensions.Spacing.indulgent)
}
}