]> git.r.bdr.sh - rbdr/map/blame - Map/Views/MapRender.swift
Make delete a context action
[rbdr/map] / Map / Views / MapRender.swift
CommitLineData
5e8ff485
RBR
1//
2// ContentView.swift
3// Map
4//
5// Created by Ruben Beltran del Rio on 2/1/21.
6//
7
77d0155b 8import Combine
5e8ff485
RBR
9import CoreData
10import CoreGraphics
11import SwiftUI
12
13struct MapRenderView: View {
14
15 @Environment(\.colorScheme) var colorScheme
16
77d0155b 17 var content: String
5e8ff485
RBR
18 let evolution: Stage
19
20 let mapSize = CGSize(width: 1300.0, height: 1000.0)
21
22 let lineWidth = CGFloat(1.0)
23 let vertexSize = CGSize(width: 25.0, height: 25.0)
24 let padding = CGFloat(30.0)
25
26 var parsedMap: ParsedMap {
77d0155b 27 return Map.parse(content: content)
5e8ff485
RBR
28 }
29
30 var body: some View {
31 ZStack(alignment: .topLeading) {
32
33 Path { path in
34 path.addRect(
35 CGRect(
36 x: -padding, y: -padding, width: mapSize.width + padding * 2,
77d0155b 37 height: mapSize.height + padding * 4))
5e8ff485
RBR
38 }.fill(MapColor.colorForScheme(colorScheme).background)
39
40 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
41 MapAxes(
42 mapSize: mapSize, lineWidth: lineWidth, evolution: evolution, stages: parsedMap.stages)
43 MapOpportunities(
44 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
45 opportunities: parsedMap.opportunities)
46 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
47 MapVertices(mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices)
48 MapEdges(
49 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
50 }.frame(
51 width: mapSize.width,
77d0155b 52 height: mapSize.height + 2 * padding, alignment: .topLeading
5e8ff485
RBR
53 ).padding(padding)
54 }
55}
56
57struct MapRenderView_Previews: PreviewProvider {
58 static var previews: some View {
77d0155b 59 MapRenderView(content: "", evolution: Stage.stages(.general)).environment(
5e8ff485
RBR
60 \.managedObjectContext, PersistenceController.preview.container.viewContext)
61 }
62}