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