Newer Older
95 lines | 3.072kb
Bogdan Timofte authored 2 weeks ago
1
//
2
//  ControlView.swift
3
//  USB Meter
4
//
5
//  Created by Bogdan Timofte on 09/03/2020.
6
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
7
//
8

            
9
import SwiftUI
10

            
11
struct ControlView: View {
12

            
13
    @EnvironmentObject private var meter: Meter
14

            
15
    var body: some View {
Bogdan Timofte authored 2 weeks ago
16
        VStack(alignment: .leading, spacing: 14) {
17
            HStack {
18
                Text("Controls")
19
                    .font(.headline)
20
                Spacer()
21
                Text(meter.reportsCurrentScreenIndex ? "Device Screen" : "Page Controls")
22
                    .font(.caption.weight(.semibold))
23
                    .foregroundColor(.secondary)
24
            }
25

            
26
            HStack(spacing: 12) {
27
                controlButton(
28
                    title: "Prev",
29
                    symbol: "chevron.left",
30
                    tint: .indigo,
31
                    action: { meter.previousScreen() }
32
                )
33

            
34
                VStack(spacing: 6) {
Bogdan Timofte authored 2 weeks ago
35
                    Text(meter.currentScreenDescription)
Bogdan Timofte authored 2 weeks ago
36
                        .font(.subheadline.weight(.semibold))
Bogdan Timofte authored 2 weeks ago
37
                        .multilineTextAlignment(.center)
Bogdan Timofte authored 2 weeks ago
38
                    if !meter.reportsCurrentScreenIndex {
39
                        Text("The protocol allows navigation, but it does not report the active page back to the app.")
40
                            .font(.caption)
41
                            .foregroundColor(.secondary)
42
                            .multilineTextAlignment(.center)
43
                    }
Bogdan Timofte authored 2 weeks ago
44
                }
Bogdan Timofte authored 2 weeks ago
45
                .frame(maxWidth: .infinity, minHeight: 92)
46
                .padding(.horizontal, 12)
47
                .meterCard(tint: meter.color, fillOpacity: 0.06, strokeOpacity: 0.10)
48

            
49
                controlButton(
50
                    title: "Next",
51
                    symbol: "chevron.right",
52
                    tint: .indigo,
53
                    action: { meter.nextScreen() }
54
                )
55
            }
56

            
57
            controlButton(
58
                title: "Rotate Screen",
59
                symbol: "rotate.right.fill",
60
                tint: .orange,
61
                compact: false,
62
                action: { meter.rotateScreen() }
63
            )
64
        }
65
    }
66

            
67
    private func controlButton(
68
        title: String,
69
        symbol: String,
70
        tint: Color,
71
        compact: Bool = true,
72
        action: @escaping () -> Void
73
    ) -> some View {
74
        Button(action: action) {
75
            VStack(spacing: 10) {
76
                Image(systemName: symbol)
77
                    .font(.system(size: compact ? 18 : 20, weight: .semibold))
78
                Text(title)
79
                    .font(.footnote.weight(.semibold))
80
                    .multilineTextAlignment(.center)
Bogdan Timofte authored 2 weeks ago
81
            }
Bogdan Timofte authored 2 weeks ago
82
            .foregroundColor(tint)
83
            .frame(maxWidth: .infinity, minHeight: compact ? 92 : 68)
84
            .padding(.horizontal, 8)
85
            .meterCard(tint: tint, fillOpacity: 0.10, strokeOpacity: 0.14)
Bogdan Timofte authored 2 weeks ago
86
        }
Bogdan Timofte authored 2 weeks ago
87
        .buttonStyle(.plain)
Bogdan Timofte authored 2 weeks ago
88
    }
89
}
90

            
91
struct ControlView_Previews: PreviewProvider {
92
    static var previews: some View {
93
        ControlView()
94
    }
95
}