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