]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Base Components/MapRender/MapNotes.swift
bbb1aba2e58581a071a7a816f34e481d7a896198
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapNotes.swift
1 import SwiftUI
2
3 struct MapNotes: View {
4
5 let mapSize: CGSize
6 let lineWidth: CGFloat
7 let notes: [Note]
8
9 let maxWidth = 400.0
10
11 var body: some View {
12 ForEach(notes, id: \.id) { note in
13 Text(note.text.replacingOccurrences(of: "\\n", with: "\n")).font(.theme.note)
14 .padding(2.0)
15 .background(.white)
16 .foregroundColor(.map.labelColor)
17 .border(Color.map.vertexColor, width: lineWidth)
18 .frame(minWidth: 16.0, maxWidth: maxWidth, alignment: .topLeading)
19 .offset(
20 CGSize(
21 width: w(note.position.x),
22 height: h(note.position.y)
23 )
24 )
25 }
26 }
27
28 func h(_ dimension: CGFloat) -> CGFloat {
29 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
30 }
31
32 func w(_ dimension: CGFloat) -> CGFloat {
33 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
34 }
35 }
36
37 #Preview {
38 MapNotes(
39 mapSize: CGSize(width: 400.0, height: 400.0), lineWidth: 1.0,
40 notes: [
41 Note(
42 id: 0, position: CGPoint(x: 50.0, y: 50.0),
43 text:
44 "Notes can have a lot more text, so we need to make sure that they're resized correctly")
45 ])
46 }