Improve content saving, label editing

This commit is contained in:
Christoph Hagen
2025-05-02 22:11:43 +02:00
parent fea06a93b7
commit 1f4f32c9af
15 changed files with 274 additions and 150 deletions

View File

@@ -0,0 +1,54 @@
import SwiftUI
struct LabelCreationView: View {
@Environment(\.colorScheme)
private var colorScheme
@Binding
var labels: [ContentLabel]
var body: some View {
List {
ForEach($labels) { label in
HStack {
Button(action: { remove(label.wrappedValue) }) {
Image(systemSymbol: .minusCircleFill)
.foregroundStyle(.red)
}
.buttonStyle(.plain)
LabelEditingView(label: label)
}
.padding(.vertical, 2)
.padding(.horizontal, 8)
.background(colorScheme == .light ? Color.white : Color.black)
.cornerRadius(8)
}
.onMove(perform: moveLabel)
Button("Add new label", action: addLabel)
.padding(.vertical, 2)
}
.frame(minHeight: 250)
}
private func addLabel() {
var label = ContentLabel(icon: .statisticsTime, value: "Value")
var number = 0
while labels.contains(label) {
number += 1
label.value = "Value \(number)"
}
labels.append(label)
}
private func remove(_ label: ContentLabel) {
guard let index = labels.firstIndex(of: label) else {
return
}
labels.remove(at: index)
}
private func moveLabel(from source: IndexSet, to destination: Int) {
labels.move(fromOffsets: source, toOffset: destination)
}
}