]> git.r.bdr.sh - rbdr/map/blame - Map/MapDetail.swift
Initial commit
[rbdr/map] / Map / MapDetail.swift
CommitLineData
1b85f723
RBR
1//
2// ContentView.swift
3// Map
4//
5// Created by Ruben Beltran del Rio on 2/1/21.
6//
7
8import SwiftUI
9import CoreData
10
11struct 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
40struct MapDetailView_Previews: PreviewProvider {
41 static var previews: some View {
42 MapDetailView(map: Map()).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
43 }
44}