// 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 enum PreferencesTab: CaseIterable { case general case editor case map case stages case templates var localizedStringKey: LocalizedStringKey { switch self { case .general: return "preferences.menu.general" case .editor: return "preferences.menu.editor" case .map: return "preferences.menu.map" case .stages: return "preferences.menu.stages" case .templates: return "preferences.menu.templates" } } var systemImage: String { switch self { case .general: return "gearshape" case .editor: return "text.word.spacing" case .map: return "map" case .stages: return "list.number" case .templates: return "doc.text" } } } struct PreferencesWindow: View { @State private var selectedTab: PreferencesTab = .general var body: some View { Group { switch selectedTab { case .general: GeneralPreferencesView() case .editor: EditorPreferencesView() case .map: MapPreferencesView() case .stages: StagesPreferencesView() case .templates: TemplatesPreferencesView() } } .frame(width: Dimensions.Preferences.Window.width, height: Dimensions.Preferences.Window.height) .toolbar { ToolbarItem(placement: .principal) { HStack(spacing: Dimensions.Spacing.loose) { ForEach(PreferencesTab.allCases, id: \.self) { tab in Button(action: { selectedTab = tab }) { VStack(spacing: Dimensions.Spacing.coziest) { Image(systemName: tab.systemImage) .font(.system(size: Dimensions.Preferences.Toolbar.size)) Text(tab.localizedStringKey) .font(.Theme.SmallControl.regular) } .frame( width: Dimensions.Preferences.Toolbar.width, height: Dimensions.Preferences.Toolbar.height ) .padding(.horizontal, Dimensions.Spacing.cozy) .background( selectedTab == tab ? Color.Theme.UI.accent : Color.background.opacity(0.01) ) .foregroundColor(selectedTab == tab ? Color.white : Color.Theme.UI.foreground) .clipShape(clipShape()) .padding(.horizontal, 2.0) } .buttonStyle(.plain) } } } } } private func clipShape() -> AnyShape { if #available(macOS 26.0, *) { AnyShape(RoundedRectangle(cornerRadius: Dimensions.Preferences.Toolbar.glassRadius)) } else { AnyShape(RoundedRectangle(cornerRadius: Dimensions.Preferences.Toolbar.radius)) } } } #Preview { PreferencesWindow() }