diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-16 12:01:07 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-16 12:01:07 +0200 |
| commit | d3e21e6050fd8cfde6ff7c68d9f8dfedf7b6301f (patch) | |
| tree | 3e9d76f8f4be7febedbd1dac01f1adc1c4c1b7db /Map | |
| parent | 45e5a80ae378a72720114641c39148c199c6332d (diff) | |
Add glass
Diffstat (limited to 'Map')
9 files changed, 182 insertions, 40 deletions
diff --git a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift index 5748e59..da67054 100644 --- a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift +++ b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift @@ -21,7 +21,7 @@ struct EvolutionPicker: View { @FocusState var isFocused: Bool @Binding var selectedEvolution: StageType - + var body: some View { Button( @@ -60,9 +60,9 @@ struct EvolutionPicker: View { ) .buttonStyle(.borderless) .background(isShowingMenu ? Color.Theme.UI.foreground : Color.clear) - .cornerRadius(4.0) + .cornerRadius(Dimensions.EvolutionPicker.radius) .overlay( - RoundedRectangle(cornerRadius: 4.0) + RoundedRectangle(cornerRadius: Dimensions.EvolutionPicker.radius) .stroke( isShowingMenu ? Color.Theme.UI.foreground : (isHovered ? Color.Theme.UI.foreground : Color.clear), diff --git a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenu.swift b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenu.swift index 73837a0..b9d76c6 100644 --- a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenu.swift +++ b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenu.swift @@ -5,7 +5,9 @@ struct EvolutionPickerMenu: View { @Binding var selectedEvolution: StageType private func select(_ stageType: StageType) { - selectedEvolution = stageType + withAnimation { + selectedEvolution = stageType + } } var body: some View { @@ -46,9 +48,8 @@ struct EvolutionPickerMenu: View { } } } - .padding(Dimensions.Spacing.coziest) - .ignoresSafeArea() - + .padding(.horizontal, Dimensions.Spacing.coziest) + .padding(.vertical, Dimensions.Spacing.regular) } } diff --git a/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift b/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift new file mode 100644 index 0000000..3b6f199 --- /dev/null +++ b/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift @@ -0,0 +1,77 @@ +// 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 + +@available(macOS 26, *) +struct GlassEvolutionPicker: View { + + @State var isShowingMenu = false + @FocusState var isFocused: Bool + + @Binding var selectedEvolution: StageType + + var body: some View { + + Button( + action: { + isShowingMenu = !isShowingMenu + }, + label: { + HStack(spacing: Dimensions.Spacing.loose) { + Text(Stage.title(selectedEvolution)) + .font(.Theme.Body.emphasized) + ZStack { + Image(systemName: "chevron.up") + .resizable() + .scaledToFit() + .frame( + width: Dimensions.EvolutionPicker.controlSize, + height: Dimensions.EvolutionPicker.controlSize + ) + .offset(CGSize(width: 0, height: -Dimensions.EvolutionPicker.controlSpacing)) + Image(systemName: "chevron.down") + .resizable() + .scaledToFit() + .frame( + width: Dimensions.EvolutionPicker.controlSize, + height: Dimensions.EvolutionPicker.controlSize + ) + .offset(CGSize(width: 0, height: Dimensions.EvolutionPicker.controlSpacing)) + } + } + .padding(.horizontal, Dimensions.Spacing.regular) + .padding(.vertical, Dimensions.Spacing.cozy) + } + ) + .buttonStyle(.glass) + .buttonBorderShape(.capsule) + .cornerRadius(Dimensions.EvolutionPicker.radius) + .popover( + isPresented: $isShowingMenu, + content: { + EvolutionPickerMenu(selectedEvolution: $selectedEvolution) + } + ) + .onChange(of: selectedEvolution) { + isShowingMenu = false + } + .animation(.bouncy, value: selectedEvolution) + } +} + +#Preview { + @Previewable @State var selectedEvolution: StageType = .behavior + EvolutionPicker(selectedEvolution: $selectedEvolution) +} diff --git a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift index bd6de42..eeccec3 100644 --- a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift +++ b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift @@ -39,7 +39,6 @@ class HoverView: NSView { private func setupView(message: String, actionLabel: String) { let box = NSBox() box.boxType = .custom - box.borderType = .lineBorder box.cornerRadius = 8 box.borderColor = NSColor.separatorColor box.fillColor = NSColor.controlBackgroundColor diff --git a/Map/Presentation/Commands/MapCommands.swift b/Map/Presentation/Commands/MapCommands.swift index a298956..fe21f57 100644 --- a/Map/Presentation/Commands/MapCommands.swift +++ b/Map/Presentation/Commands/MapCommands.swift @@ -62,6 +62,9 @@ struct MapCommands: Commands { Button("commands.file.export") { if let selectedEvolution, let document { if let image = document.exportAsImage(withEvolution: selectedEvolution) { + + // Capture image data to avoid sendability issues with NSImage + guard let tiffData = image.tiffRepresentation else { return } let filename = url?.deletingPathExtension().lastPathComponent ?? "Untitled" @@ -154,9 +157,11 @@ struct MapCommands: Commands { savePanel.accessoryView = accessoryController.view savePanel.begin { result in - if result == .OK, let url = savePanel.url { - if let tiffRepresentation = image.tiffRepresentation { - let bitmapImage = NSBitmapImageRep(data: tiffRepresentation) + if result == .OK { + let bitmapImage = NSBitmapImageRep(data: tiffData) + + Task { @MainActor in + guard let url = savePanel.url else { return } let selectedFormat = formats[accessoryController.formatPopup.indexOfSelectedItem] // Generate data based on selected format diff --git a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift index fe98ace..ce95813 100644 --- a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift +++ b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift @@ -127,9 +127,15 @@ struct MapRenderView: View { MapVertices( mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices, labelPositions: smartLabelPositions, onDragVertex: onDragVertex) - MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup( - opaque: true - ).opacity(0.1) + if #available(macOS 26.0, *) { + MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups) + .drawingGroup() + .opacity(0.1) + } else { + MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup( + opaque: true + ).opacity(0.1) + } MapNotes( mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes) } diff --git a/Map/Presentation/MapEditor.swift b/Map/Presentation/MapEditor.swift index f9a8dae..f5589e5 100644 --- a/Map/Presentation/MapEditor.swift +++ b/Map/Presentation/MapEditor.swift @@ -142,7 +142,9 @@ struct MapEditor: View { .onChange(of: document.text) { _, _ in buildVertexLineMap() } - }.background(Color.Theme.UI.background) + .padding(.bottom, Dimensions.MapEditor.additionalPadding) + } + .background(Color.Theme.UI.background) .gesture( MagnificationGesture() .onChanged { value in @@ -156,30 +158,64 @@ struct MapEditor: View { ) } } - Divider() - HStack { - Spacer() - Slider( - value: $zoom, in: zoomRange, step: 0.1, - label: { - Text(formatZoom(zoom)) - .font(.Theme.SmallControl.regular) - }, - minimumValueLabel: { - Image(systemName: "minus.magnifyingglass") - .font(.Theme.SmallControl.regular) - .help("map_editor.zoom_out") - }, - maximumValueLabel: { - Image(systemName: "plus.magnifyingglass") - .font(.Theme.SmallControl.regular) - .help("map_editor.zoom_in") - } - ).frame(width: 200).padding(.trailing, 10.0) - }.padding(4.0) - }.toolbar { - ToolbarItem(placement: .primaryAction) { - EvolutionPicker(selectedEvolution: $selectedEvolution) + + if #unavailable(macOS 26) { + Divider() + HStack { + Spacer() + Slider( + value: $zoom, in: zoomRange, step: 0.1, + label: { + Text(formatZoom(zoom)) + .font(.Theme.SmallControl.regular) + }, + minimumValueLabel: { + Image(systemName: "minus.magnifyingglass") + .font(.Theme.SmallControl.regular) + .help("map_editor.zoom_out") + }, + maximumValueLabel: { + Image(systemName: "plus.magnifyingglass") + .font(.Theme.SmallControl.regular) + .help("map_editor.zoom_in") + } + ).frame(width: 200).padding(.trailing, 10.0) + }.padding(4.0) + } + } + .safeAreaInset(edge: .bottom, alignment: .trailing) { + if #available(macOS 26, *) { + HStack { + Slider( + value: $zoom, in: zoomRange, step: 0.1, + label: { + Text(formatZoom(zoom)) + .font(.Theme.SmallControl.regular) + }, + minimumValueLabel: { + Image(systemName: "minus.magnifyingglass") + .font(.Theme.SmallControl.regular) + .help("map_editor.zoom_out") + }, + maximumValueLabel: { + Image(systemName: "plus.magnifyingglass") + .font(.Theme.SmallControl.regular) + .help("map_editor.zoom_in") + } + ).frame(width: 200) + .padding(Dimensions.Spacing.regular) + .glassEffect(.regular) + GlassEvolutionPicker(selectedEvolution: $selectedEvolution) + } + .padding(Dimensions.Spacing.regular) + + } + } + .toolbar { + if #unavailable(macOS 26) { + ToolbarItem(placement: .primaryAction) { + EvolutionPicker(selectedEvolution: $selectedEvolution) + } } } .focusedSceneValue(\.isSearching, $isSearching) diff --git a/Map/Presentation/Preferences/TemplatesPreferencesView.swift b/Map/Presentation/Preferences/TemplatesPreferencesView.swift index 51d1c5e..aab73ef 100644 --- a/Map/Presentation/Preferences/TemplatesPreferencesView.swift +++ b/Map/Presentation/Preferences/TemplatesPreferencesView.swift @@ -127,6 +127,7 @@ struct TemplatesPreferencesView: View { HStack(spacing: Dimensions.Spacing.coziest) { Button(action: { showingAddSheet = true }) { Image(systemName: "plus") + .frame(width: 12, height: 12) } .keyboardShortcut("t", modifiers: [.command]) .help("preferences.templates.help.add") @@ -135,6 +136,7 @@ struct TemplatesPreferencesView: View { removeTemplate(selectedTemplate) }) { Image(systemName: "minus") + .frame(width: 12, height: 12) } .keyboardShortcut(.delete, modifiers: [.command]) .help("preferences.templates.help.remove \(selectedTemplate?.name ?? "")") diff --git a/Map/Presentation/Theme/Dimensions.swift b/Map/Presentation/Theme/Dimensions.swift index 26b4496..57bd8b8 100644 --- a/Map/Presentation/Theme/Dimensions.swift +++ b/Map/Presentation/Theme/Dimensions.swift @@ -79,11 +79,27 @@ struct Dimensions { // MARK: - Assorted Controls struct EvolutionPicker { - static let radius = 8.0 + static var radius: CGFloat { + if #available(macOS 26, *) { + return 12.0 + } else { + return 4.0 + } + } static let controlSize = 8.0 static let controlSpacing = 3.0 } + struct MapEditor { + static var additionalPadding: CGFloat { + if #available(macOS 26, *) { + return 32.0 + } else { + return 0.0 + } + } + } + struct Preferences { struct Window { |