Improve content saving, label editing
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user