Merge pull request #786 from meshtastic/iaq-legend

IAQ legend popower
This commit is contained in:
Garth Vander Houwen 2024-07-10 20:53:19 -07:00 committed by GitHub
commit 321a41d3f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 58 additions and 45 deletions

View file

@ -8530,6 +8530,9 @@
},
"Indoor Air Quality" : {
},
"Indoor Air Quality (IAQ)" : {
},
"inputevent.back" : {
"extractionState" : "migrated",

View file

@ -603,8 +603,8 @@
DD5E523E298F5A9E00D21B61 /* AirQualityIndex.swift */,
DDFEB3BA29900C1200EE7472 /* CurrentConditionsCompact.swift */,
DDA9515D2BC6F56F00CEA535 /* IndoorAirQuality.swift */,
DD41A61429AB0035003C5A37 /* NodeWeatherForecast.swift */,
DD354FD82BD96A0B0061A25F /* IAQScale.swift */,
DD41A61429AB0035003C5A37 /* NodeWeatherForecast.swift */,
);
path = Weather;
sourceTree = "<group>";

View file

@ -11,6 +11,8 @@ struct IAQScale: View {
var body: some View {
VStack(alignment: .leading) {
Text("Indoor Air Quality (IAQ)")
.font(.title3)
ForEach(Iaq.allCases) { iaq in
HStack {
RoundedRectangle(cornerRadius: 5)
@ -22,11 +24,6 @@ struct IAQScale: View {
}
}
.padding()
.background(.thinMaterial, in: RoundedRectangle(cornerRadius: 20, style: .continuous))
// .overlay(
// RoundedRectangle(cornerRadius: 20)
// .stroke(.secondary, lineWidth: 5)
// )
}
}

View file

@ -20,59 +20,70 @@ enum IaqDisplayMode: Int, CaseIterable, Identifiable {
}
struct IndoorAirQuality: View {
@State var isLegendOpen = false
var iaq: Int = 0
var displayMode: IaqDisplayMode = .pill
let gradient = Gradient(colors: [.green, .mint, .yellow, .orange, .red, .purple, .purple, .brown, .brown, .brown, .brown])
var body: some View {
let iaqEnum = Iaq.getIaq(for: iaq)
switch displayMode {
case .pill:
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 10)
.fill(iaqEnum.color)
.frame(width: 125, height: 30)
Label("IAQ \(iaq)", systemImage: iaq < 100 ? "aqi.low" : ((iaq > 100 && iaq < 201) ? "aqi.medium" : "aqi.high"))
.padding(.leading, 4)
}
case .dot:
VStack {
HStack {
Text("\(iaq)")
Circle()
VStack {
switch displayMode {
case .pill:
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 10)
.fill(iaqEnum.color)
.frame(width: 10, height: 10)
.frame(width: 125, height: 30)
Label("IAQ \(iaq)", systemImage: iaq < 100 ? "aqi.low" : ((iaq > 100 && iaq < 201) ? "aqi.medium" : "aqi.high"))
.padding(.leading, 4)
}
}
case .text:
Text(iaqEnum.description)
.font(.caption)
case .gauge:
Gauge(value: Double(iaq), in: 0...500) {
case .dot:
VStack {
HStack {
Text("\(iaq)")
Circle()
.fill(iaqEnum.color)
.frame(width: 10, height: 10)
}
}
case .text:
Text(iaqEnum.description)
.font(.caption)
case .gauge:
Gauge(value: Double(iaq), in: 0...500) {
Text("IAQ")
.foregroundColor(iaqEnum.color)
} currentValueLabel: {
Text("\(Int(iaq))")
}
.tint(gradient)
.gaugeStyle(.accessoryCircular)
case .gradient:
HStack {
Gauge(value: Double(iaq), in: 0...500) {
Text("IAQ")
.foregroundColor(iaqEnum.color)
} currentValueLabel: {
Text("\(Int(iaq))")
Text("IAQ ")+Text("\(Int(iaq))")
.foregroundColor(.gray)
}
.tint(gradient)
.gaugeStyle(.accessoryCircular)
case .gradient:
HStack {
Gauge(value: Double(iaq), in: 0...500) {
Text("IAQ")
.foregroundColor(iaqEnum.color)
} currentValueLabel: {
Text("IAQ ")+Text("\(Int(iaq))")
.foregroundColor(.gray)
}
.tint(gradient)
.gaugeStyle(.accessoryLinear)
Text(iaqEnum.description)
.font(.caption)
.gaugeStyle(.accessoryLinear)
Text(iaqEnum.description)
.font(.caption)
}
.padding([.leading, .trailing])
}
.padding([.leading, .trailing])
}
.onTapGesture {
isLegendOpen.toggle()
}
.popover(isPresented: self.$isLegendOpen, arrowEdge: .bottom, content: {
VStack(spacing: 0.5) {
IAQScale()
}
.presentationCompactAdaptation(.popover)
})
}
}

View file

@ -20,6 +20,7 @@ struct NodeInfoItem: View {
var body: some View {
HStack {
Spacer()
CircleText(
text: node.user?.shortName ?? "?",
color: Color(UIColor(hex: UInt32(node.num))),
@ -68,6 +69,7 @@ struct NodeInfoItem: View {
BatteryGauge(node: node)
.padding()
}
Spacer()
}
.padding(.leading)
}

@ -1 +1 @@
Subproject commit 0fd5023a0aa67eefdf2292a624e8fbbda4489a6c
Subproject commit d191975ebc572527c6d9eec48d5b0a1e3331999f