Showing 3 changed files with 28 additions and 49 deletions
+1 -1
USB Meter/Views/Meter/MeterSettingsView.swift
@@ -88,7 +88,7 @@ struct MeterSettingsView: View {
88 88
             .ignoresSafeArea()
89 89
         )
90 90
         .navigationBarTitle("Meter Settings")
91
-        .navigationBarItems( trailing: RSSIView( RSSI: meter.btSerial.RSSI ).frame( width: 24 ) )
91
+        .navigationBarItems( trailing: RSSIView( RSSI: meter.btSerial.RSSI ).frame( width: 18, height: 18 ) )
92 92
     }
93 93
 
94 94
     private func settingsCard<Content: View>(
+4 -5
USB Meter/Views/Meter/MeterView.swift
@@ -64,21 +64,20 @@ struct MeterView: View {
64 64
             .ignoresSafeArea()
65 65
         )
66 66
         .navigationBarTitle("Meter")
67
-        .navigationBarItems(trailing: HStack (spacing: 0) {
67
+        .navigationBarItems(trailing: HStack (spacing: 6) {
68 68
             if meter.operationalState > .notPresent {
69 69
                 RSSIView(RSSI: meter.btSerial.RSSI)
70
-                    .frame(width: 24)
70
+                    .frame(width: 18, height: 18)
71
+                    .padding(.leading, 6)
71 72
                     .padding(.vertical)
72 73
             }
73 74
             NavigationLink(destination: MeterInfoView().environmentObject(meter)) {
74 75
                 Image(systemName: "info.circle.fill")
75 76
                     .padding(.vertical)
76
-                    .padding(.leading)
77 77
             }
78 78
             NavigationLink(destination: MeterSettingsView().environmentObject(meter)) {
79 79
                 Image(systemName: "gearshape.fill")
80 80
                     .padding(.vertical)
81
-                    .padding(.leading)
82 81
             }
83 82
         })
84 83
     }
@@ -296,7 +295,7 @@ private struct MeterInfoView: View {
296 295
             .ignoresSafeArea()
297 296
         )
298 297
         .navigationBarTitle("Meter Info")
299
-        .navigationBarItems(trailing: RSSIView(RSSI: meter.btSerial.RSSI).frame(width: 24))
298
+        .navigationBarItems(trailing: RSSIView(RSSI: meter.btSerial.RSSI).frame(width: 18, height: 18))
300 299
     }
301 300
 }
302 301
 
+23 -43
USB Meter/Views/Meter/RSSIView.swift
@@ -12,52 +12,32 @@ import SwiftUI
12 12
 struct RSSIView: View {
13 13
     
14 14
     var RSSI: Int
15
+    private let barThresholds = [-100, -85, -70, -55]
16
+    private let barHeights: [CGFloat] = [5, 8, 11, 14]
15 17
     
16 18
     var body: some View {
17
-        GeometryReader { box in
18
-            HStack (alignment: VerticalAlignment.bottom, spacing: 3) {
19
-                ZStack {
20
-                    Rectangle().stroke()
21
-                    if self.RSSI >= -110 {
22
-                        Rectangle()
23
-                            .foregroundColor(self.clr())
24
-                    }
25
-                }
26
-                .frame(height: box.size.height * 0.2)
27
-                ZStack {
28
-                    Rectangle().stroke()
29
-                    if self.RSSI >= -100 {
30
-                        Rectangle()
31
-                        .foregroundColor(self.clr())
32
-                    }
33
-                }
34
-                .frame(height: box.size.height * 0.4)
35
-                ZStack {
36
-                    Rectangle().stroke()
37
-                    if self.RSSI >= -80 {
38
-                        Rectangle()
39
-                        .foregroundColor(self.clr())
40
-                    }
41
-                }
42
-                .frame(height: box.size.height * 0.6)
43
-                ZStack {
44
-                    Rectangle().stroke()
45
-                    if self.RSSI >= -60 {
46
-                        Rectangle()
47
-                        .foregroundColor(self.clr())
48
-                    }
49
-                }
50
-                .frame(height: box.size.height * 0.8)
51
-                ZStack {
52
-                    Rectangle().stroke()
53
-                    if self.RSSI >= -50 {
54
-                        Rectangle()
55
-                        .foregroundColor(self.clr())
56
-                    }
57
-                }
58
-                .frame(height: box.size.height/1)
19
+        HStack(alignment: .bottom, spacing: 2) {
20
+            ForEach(Array(barHeights.enumerated()), id: \.offset) { index, height in
21
+                RoundedRectangle(cornerRadius: 1.2, style: .continuous)
22
+                    .stroke(barStrokeColor(for: index), lineWidth: 1)
23
+                    .background(
24
+                        RoundedRectangle(cornerRadius: 1.2, style: .continuous)
25
+                            .fill(index < activeBarCount ? clr() : Color.clear)
26
+                    )
27
+                    .frame(width: 3, height: height)
59 28
             }
60 29
         }
30
+        .frame(width: 18, height: 16, alignment: .bottom)
31
+    }
32
+
33
+    private var activeBarCount: Int {
34
+        barThresholds.reduce(0) { count, threshold in
35
+            count + (RSSI >= threshold ? 1 : 0)
36
+        }
37
+    }
38
+
39
+    private func barStrokeColor(for index: Int) -> Color {
40
+        index < activeBarCount ? clr().opacity(0.65) : Color.secondary.opacity(0.35)
61 41
     }
62 42
 
63 43
     private func clr() -> Color {
@@ -76,6 +56,6 @@ struct RSSIView: View {
76 56
 
77 57
 struct SwiftUIView_Previews: PreviewProvider {
78 58
     static var previews: some View {
79
-        RSSIView(RSSI: -80).frame(width: 64, height: 64, alignment: .center)
59
+        RSSIView(RSSI: -80).frame(width: 20, height: 20, alignment: .center)
80 60
     }
81 61
 }