| 1 |
// |
|
| 2 |
// MeasurementView.swift |
|
| 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 | ||
| 11 |
struct MeasurementsView: View {
|
|
| 12 | ||
| 13 |
@EnvironmentObject private var measurements: Measurements |
|
| 14 | ||
| 15 |
@Binding var visibility: Bool |
|
| 16 | ||
| 17 |
var body: some View {
|
|
| 18 |
NavigationView {
|
|
| 19 |
VStack {
|
|
| 20 |
List {
|
|
| 21 |
ForEach (measurements.power.points) { point in
|
|
| 22 |
// MARK: Crapa la stergere daca lista incape in fereastra: Fatal error: Index out of range |
|
| 23 |
MeasurementPointView(power: point, voltage: self.measurements.voltage.points[point.id], current: self.measurements.current.points[point.id]) |
|
| 24 |
}.onDelete { (indexSet) in
|
|
| 25 |
for idx in indexSet {
|
|
| 26 |
self.measurements.remove(at: idx) |
|
| 27 |
} |
|
| 28 |
} |
|
| 29 |
} |
|
| 30 |
} |
|
| 31 |
.navigationBarItems(leading: HStack{
|
|
| 32 |
#if targetEnvironment(macCatalyst) |
|
| 33 |
Button(action: {self.visibility.toggle()}) {
|
|
| 34 |
Text("ⓧ")
|
|
| 35 |
.foregroundColor(.red) |
|
| 36 |
} |
|
| 37 |
#else |
|
| 38 |
Spacer() |
|
| 39 |
#endif |
|
| 40 |
}, |
|
| 41 |
trailing: HStack{
|
|
| 42 |
#if targetEnvironment(macCatalyst) |
|
| 43 |
EditButton() |
|
| 44 |
#endif |
|
| 45 |
Button(action: {
|
|
| 46 |
self.measurements.power.reset() |
|
| 47 |
self.measurements.voltage.reset() |
|
| 48 |
self.measurements.current.reset() |
|
| 49 |
}) {
|
|
| 50 |
Text("🗑")
|
|
| 51 |
.foregroundColor(.red) |
|
| 52 |
} |
|
| 53 |
}) |
|
| 54 |
.navigationBarTitle("Measurements", displayMode: .inline)
|
|
| 55 |
} |
|
| 56 |
.navigationViewStyle(StackNavigationViewStyle()) |
|
| 57 |
} |
|
| 58 |
} |