]> git.r.bdr.sh - rbdr/map/blame_incremental - Map/MapRenderComponents/MapBlockers.swift
Release 1.1.0
[rbdr/map] / Map / MapRenderComponents / MapBlockers.swift
... / ...
CommitLineData
1import SwiftUI
2
3struct MapBlockers: View {
4
5 @Environment(\.colorScheme) var colorScheme
6
7 let mapSize: CGSize
8 let vertexSize: CGSize
9 let blockers: [Blocker]
10
11 var color: Color {
12 MapColor.colorForScheme(colorScheme).blocker
13 }
14
15 let cornerSize = CGSize(width: 2.0, height: 2.0)
16
17 var body: some View {
18 ForEach(blockers, id: \.id) { vertex in
19 Path { path in
20 path.addRoundedRect(
21 in: CGRect(
22 origin: CGPoint(
23 x: w(vertex.position.x) + 3 * vertexSize.width,
24 y: h(vertex.position.y) - vertexSize.height * 2 / 3),
25 size: CGSize(width: vertexSize.width / 2, height: vertexSize.height * 2)
26 ), cornerSize: cornerSize)
27 }.fill(color)
28 }
29 }
30
31 func h(_ dimension: CGFloat) -> CGFloat {
32 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
33 }
34
35 func w(_ dimension: CGFloat) -> CGFloat {
36 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
37 }
38}
39
40struct MapBlockers_Previews: PreviewProvider {
41 static var previews: some View {
42 MapBlockers(
43 mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
44 blockers: [
45 Blocker(id: 0, position: CGPoint(x: 50.0, y: 50.0)),
46 Blocker(id: 1, position: CGPoint(x: 10.0, y: 20.0)),
47 ])
48 }
49}