blob: 74e3c8dd89d3eb44c247bbd3e57f18c75e431375 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
//
// ContentView.swift
// Map
//
// Created by Ruben Beltran del Rio on 2/1/21.
//
import SwiftUI
import CoreData
struct MapDetailView: View {
@Environment(\.managedObjectContext) private var viewContext
@ObservedObject var map: Map
@State private var selectedEvolution = StageType.General
var body: some View {
VSplitView {
VStack {
TextField("Title", text: Binding($map.title, ""), onCommit: {
try? viewContext.save()
})
Picker("Evolution", selection: $selectedEvolution) {
ForEach(StageType.allCases) { stage in
Text(Stage.title(stage)).tag(stage)
}
}
TextEditor(text: Binding($map.content, "")).onChange(of: map.content) { _ in
try? viewContext.save()
}.font(Font.system(size: 16, design: .monospaced))
}
ScrollView([.horizontal, .vertical]) {
MapRenderView(map: map, evolution: Stage.stages(selectedEvolution))
}
}
}
}
struct MapDetailView_Previews: PreviewProvider {
static var previews: some View {
MapDetailView(map: Map()).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}
|