|
Bogdan Timofte
authored
2 weeks ago
|
1
|
//
|
|
Bogdan Timofte
authored
a week ago
|
2
|
// MeterScreenControlsView.swift
|
|
Bogdan Timofte
authored
2 weeks ago
|
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
|
|
|
Bogdan Timofte
authored
a week ago
|
11
|
struct MeterScreenControlsView: View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
12
|
|
|
|
13
|
@EnvironmentObject private var meter: Meter
|
|
Bogdan Timofte
authored
2 weeks ago
|
14
|
var compactLayout: Bool = false
|
|
|
15
|
var availableSize: CGSize? = nil
|
|
Bogdan Timofte
authored
2 weeks ago
|
16
|
var showsHeader: Bool = true
|
|
Bogdan Timofte
authored
2 weeks ago
|
17
|
|
|
|
18
|
var body: some View {
|
|
Bogdan Timofte
authored
2 weeks ago
|
19
|
VStack(alignment: .leading, spacing: 14) {
|
|
Bogdan Timofte
authored
2 weeks ago
|
20
|
if showsHeader {
|
|
|
21
|
HStack {
|
|
|
22
|
Text("Controls")
|
|
|
23
|
.font(.headline)
|
|
|
24
|
Spacer()
|
|
|
25
|
Text(meter.reportsCurrentScreenIndex ? "Device Screen" : "Page Controls")
|
|
|
26
|
.font(.caption.weight(.semibold))
|
|
|
27
|
.foregroundColor(.secondary)
|
|
|
28
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
29
|
}
|
|
|
30
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
31
|
if compactLayout {
|
|
|
32
|
if usesExpandedCompactLayout {
|
|
|
33
|
Spacer(minLength: 0)
|
|
|
34
|
|
|
|
35
|
VStack(spacing: 12) {
|
|
|
36
|
HStack(spacing: 12) {
|
|
Bogdan Timofte
authored
a week ago
|
37
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
38
|
title: "Prev",
|
|
|
39
|
symbol: "chevron.left",
|
|
|
40
|
tint: .indigo,
|
|
Bogdan Timofte
authored
a week ago
|
41
|
compact: true,
|
|
|
42
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
43
|
action: { meter.previousScreen() }
|
|
|
44
|
)
|
|
|
45
|
|
|
Bogdan Timofte
authored
a week ago
|
46
|
MeterCurrentScreenSummaryView(
|
|
Bogdan Timofte
authored
a week ago
|
47
|
reportsCurrentScreenIndex: meter.reportsCurrentScreenIndex,
|
|
|
48
|
currentScreenDescription: meter.currentScreenDescription,
|
|
|
49
|
isExpandedCompactLayout: usesExpandedCompactLayout
|
|
|
50
|
)
|
|
Bogdan Timofte
authored
2 weeks ago
|
51
|
.frame(maxWidth: .infinity, minHeight: 112)
|
|
|
52
|
.padding(.horizontal, 14)
|
|
|
53
|
.meterCard(tint: meter.color, fillOpacity: 0.06, strokeOpacity: 0.10)
|
|
|
54
|
}
|
|
|
55
|
|
|
|
56
|
HStack(spacing: 12) {
|
|
Bogdan Timofte
authored
a week ago
|
57
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
58
|
title: "Rotate",
|
|
|
59
|
symbol: "rotate.right.fill",
|
|
|
60
|
tint: .orange,
|
|
Bogdan Timofte
authored
a week ago
|
61
|
compact: true,
|
|
|
62
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
63
|
action: { meter.rotateScreen() }
|
|
|
64
|
)
|
|
|
65
|
|
|
Bogdan Timofte
authored
a week ago
|
66
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
67
|
title: "Next",
|
|
|
68
|
symbol: "chevron.right",
|
|
|
69
|
tint: .indigo,
|
|
Bogdan Timofte
authored
a week ago
|
70
|
compact: true,
|
|
|
71
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
72
|
action: { meter.nextScreen() }
|
|
|
73
|
)
|
|
|
74
|
}
|
|
|
75
|
}
|
|
|
76
|
|
|
|
77
|
Spacer(minLength: 0)
|
|
|
78
|
} else {
|
|
|
79
|
HStack(spacing: 10) {
|
|
Bogdan Timofte
authored
a week ago
|
80
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
81
|
title: "Prev",
|
|
|
82
|
symbol: "chevron.left",
|
|
|
83
|
tint: .indigo,
|
|
Bogdan Timofte
authored
a week ago
|
84
|
compact: true,
|
|
|
85
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
86
|
action: { meter.previousScreen() }
|
|
|
87
|
)
|
|
Bogdan Timofte
authored
2 weeks ago
|
88
|
|
|
Bogdan Timofte
authored
a week ago
|
89
|
MeterCurrentScreenSummaryView(
|
|
Bogdan Timofte
authored
a week ago
|
90
|
reportsCurrentScreenIndex: meter.reportsCurrentScreenIndex,
|
|
|
91
|
currentScreenDescription: meter.currentScreenDescription,
|
|
|
92
|
isExpandedCompactLayout: usesExpandedCompactLayout
|
|
|
93
|
)
|
|
Bogdan Timofte
authored
2 weeks ago
|
94
|
.frame(maxWidth: .infinity, minHeight: 82)
|
|
|
95
|
.padding(.horizontal, 10)
|
|
|
96
|
.meterCard(tint: meter.color, fillOpacity: 0.06, strokeOpacity: 0.10)
|
|
|
97
|
|
|
Bogdan Timofte
authored
a week ago
|
98
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
99
|
title: "Rotate",
|
|
|
100
|
symbol: "rotate.right.fill",
|
|
|
101
|
tint: .orange,
|
|
Bogdan Timofte
authored
a week ago
|
102
|
compact: true,
|
|
|
103
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
104
|
action: { meter.rotateScreen() }
|
|
|
105
|
)
|
|
|
106
|
|
|
Bogdan Timofte
authored
a week ago
|
107
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
108
|
title: "Next",
|
|
|
109
|
symbol: "chevron.right",
|
|
|
110
|
tint: .indigo,
|
|
Bogdan Timofte
authored
a week ago
|
111
|
compact: true,
|
|
|
112
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
113
|
action: { meter.nextScreen() }
|
|
|
114
|
)
|
|
|
115
|
}
|
|
|
116
|
}
|
|
|
117
|
} else {
|
|
|
118
|
HStack(spacing: 12) {
|
|
Bogdan Timofte
authored
a week ago
|
119
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
120
|
title: "Prev",
|
|
|
121
|
symbol: "chevron.left",
|
|
|
122
|
tint: .indigo,
|
|
Bogdan Timofte
authored
a week ago
|
123
|
compact: true,
|
|
|
124
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
125
|
action: { meter.previousScreen() }
|
|
|
126
|
)
|
|
|
127
|
|
|
Bogdan Timofte
authored
a week ago
|
128
|
MeterCurrentScreenSummaryView(
|
|
Bogdan Timofte
authored
a week ago
|
129
|
reportsCurrentScreenIndex: meter.reportsCurrentScreenIndex,
|
|
|
130
|
currentScreenDescription: meter.currentScreenDescription,
|
|
|
131
|
isExpandedCompactLayout: usesExpandedCompactLayout
|
|
|
132
|
)
|
|
Bogdan Timofte
authored
2 weeks ago
|
133
|
.frame(maxWidth: .infinity, minHeight: 92)
|
|
|
134
|
.padding(.horizontal, 12)
|
|
|
135
|
.meterCard(tint: meter.color, fillOpacity: 0.06, strokeOpacity: 0.10)
|
|
|
136
|
|
|
Bogdan Timofte
authored
a week ago
|
137
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
138
|
title: "Next",
|
|
|
139
|
symbol: "chevron.right",
|
|
|
140
|
tint: .indigo,
|
|
Bogdan Timofte
authored
a week ago
|
141
|
compact: true,
|
|
|
142
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
143
|
action: { meter.nextScreen() }
|
|
|
144
|
)
|
|
|
145
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
146
|
|
|
Bogdan Timofte
authored
a week ago
|
147
|
MeterScreenControlButtonView(
|
|
Bogdan Timofte
authored
2 weeks ago
|
148
|
title: "Rotate Screen",
|
|
|
149
|
symbol: "rotate.right.fill",
|
|
|
150
|
tint: .orange,
|
|
|
151
|
compact: false,
|
|
Bogdan Timofte
authored
a week ago
|
152
|
isExpandedCompactLayout: usesExpandedCompactLayout,
|
|
Bogdan Timofte
authored
2 weeks ago
|
153
|
action: { meter.rotateScreen() }
|
|
Bogdan Timofte
authored
2 weeks ago
|
154
|
)
|
|
|
155
|
}
|
|
|
156
|
}
|
|
Bogdan Timofte
authored
2 weeks ago
|
157
|
.frame(maxWidth: .infinity, maxHeight: compactLayout ? .infinity : nil, alignment: .topLeading)
|
|
Bogdan Timofte
authored
2 weeks ago
|
158
|
}
|
|
|
159
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
160
|
private var usesExpandedCompactLayout: Bool {
|
|
|
161
|
compactLayout && (availableSize?.height ?? 0) >= 520
|
|
|
162
|
}
|
|
|
163
|
|
|
Bogdan Timofte
authored
2 weeks ago
|
164
|
}
|
|
|
165
|
|
|
Bogdan Timofte
authored
a week ago
|
166
|
struct MeterScreenControlsView_Previews: PreviewProvider {
|
|
Bogdan Timofte
authored
2 weeks ago
|
167
|
static var previews: some View {
|
|
Bogdan Timofte
authored
a week ago
|
168
|
MeterScreenControlsView()
|
|
Bogdan Timofte
authored
2 weeks ago
|
169
|
}
|
|
|
170
|
}
|