]> git.r.bdr.sh - rbdr/map/blame_incremental - Map/Views/MapRender.swift
Add sidebar menu
[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 Combine
9import CoreData
10import CoreGraphics
11import SwiftUI
12
13struct MapRenderView: View {
14
15 @Environment(\.colorScheme) var colorScheme
16
17 var content: String
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 {
27 return Map.parse(content: content)
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,
37 height: mapSize.height + padding * 4))
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,
52 height: mapSize.height + 2 * padding, alignment: .topLeading
53 ).padding(padding)
54 }
55}
56
57struct MapRenderView_Previews: PreviewProvider {
58 static var previews: some View {
59 MapRenderView(content: "", evolution: Stage.stages(.general)).environment(
60 \.managedObjectContext, PersistenceController.preview.container.viewContext)
61 }
62}