aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Preferences/EditorPreferencesView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Map/Presentation/Preferences/EditorPreferencesView.swift')
-rw-r--r--Map/Presentation/Preferences/EditorPreferencesView.swift120
1 files changed, 120 insertions, 0 deletions
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()
+}