Newer Older
69 lines | 2.476kb
Bogdan Timofte authored 2 weeks ago
1
//
Bogdan Timofte authored a week ago
2
//  MeasurementSeriesSampleView.swift
Bogdan Timofte authored 2 weeks ago
3
//  USB Meter
4
//
5
//  Created by Bogdan Timofte on 13/04/2020.
6
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
7
//
8

            
9
import SwiftUI
10

            
Bogdan Timofte authored a week ago
11
struct MeasurementSeriesSampleView: View {
Bogdan Timofte authored 2 weeks ago
12

            
13
    var power: Measurements.Measurement.Point
14
    var voltage: Measurements.Measurement.Point
15
    var current: Measurements.Measurement.Point
16

            
17
    @State var showDetail: Bool = false
18

            
19
    var body: some View {
Bogdan Timofte authored 2 weeks ago
20
        VStack(alignment: .leading, spacing: 12) {
21
            HStack(spacing: 12) {
22
                Image(systemName: "waveform.path.ecg.rectangle.fill")
23
                    .foregroundColor(.blue)
24
                    .frame(width: 36, height: 36)
25
                    .background(Circle().fill(Color.blue.opacity(0.16)))
26
                VStack(alignment: .leading, spacing: 3) {
27
                    Text(voltage.timestamp.format(as: "yyyy-MM-dd HH:mm:ss"))
28
                        .font(.subheadline.weight(.semibold))
29
                    Text("Captured sample")
30
                        .font(.caption)
31
                        .foregroundColor(.secondary)
32
                }
Bogdan Timofte authored 2 weeks ago
33
                Spacer()
34
                Button(action: {
Bogdan Timofte authored 2 weeks ago
35
                    showDetail.toggle()
Bogdan Timofte authored 2 weeks ago
36
                }) {
Bogdan Timofte authored 2 weeks ago
37
                    Image(systemName: "chevron.right.circle.fill")
Bogdan Timofte authored 2 weeks ago
38
                        .imageScale(.large)
Bogdan Timofte authored 2 weeks ago
39
                        .foregroundColor(.secondary)
Bogdan Timofte authored 2 weeks ago
40
                        .rotationEffect(.degrees(showDetail ? 90 : 0))
Bogdan Timofte authored 2 weeks ago
41
                        .animation(.easeInOut(duration: 0.25), value: showDetail)
Bogdan Timofte authored 2 weeks ago
42
                }
Bogdan Timofte authored 2 weeks ago
43
                .buttonStyle(.plain)
Bogdan Timofte authored 2 weeks ago
44
            }
Bogdan Timofte authored 2 weeks ago
45

            
Bogdan Timofte authored 2 weeks ago
46
            if showDetail {
Bogdan Timofte authored 2 weeks ago
47
                VStack(spacing: 10) {
48
                    detailRow(title: "Power", value: "\(power.value.format(fractionDigits: 4)) W")
49
                    detailRow(title: "Voltage", value: "\(voltage.value.format(fractionDigits: 4)) V")
50
                    detailRow(title: "Current", value: "\(current.value.format(fractionDigits: 4)) A")
Bogdan Timofte authored 2 weeks ago
51
                }
52
            }
53
        }
Bogdan Timofte authored 2 weeks ago
54
        .padding(16)
55
        .meterCard(tint: .blue, fillOpacity: 0.14, strokeOpacity: 0.20, cornerRadius: 18)
56
    }
57

            
58
    private func detailRow(title: String, value: String) -> some View {
59
        HStack {
60
            Text(title)
61
                .foregroundColor(.secondary)
62
            Spacer()
63
            Text(value)
64
                .fontWeight(.semibold)
65
                .monospacedDigit()
66
        }
67
        .font(.footnote)
Bogdan Timofte authored 2 weeks ago
68
    }
69
}