feat: Adds text labeled content and style.
This commit is contained in:
@@ -26,13 +26,13 @@ public struct EquipmentSettingsForm {
|
||||
public var includesFilterDrop: Bool
|
||||
public var equipmentType: EquipmentMeasurement.EquipmentType
|
||||
public var focusedField: Field? = nil
|
||||
@Shared public var sharedSettings: SharedPressureEstimationSettings
|
||||
@Shared public var sharedSettings: SharedPressureEstimationState
|
||||
|
||||
public init(
|
||||
destination: Destination.State? = nil,
|
||||
includesFilterDrop: Bool = false,
|
||||
equipmentType: EquipmentMeasurement.EquipmentType = .airHandler,
|
||||
sharedSettings: Shared<SharedPressureEstimationSettings>
|
||||
sharedSettings: Shared<SharedPressureEstimationState>
|
||||
) {
|
||||
self.destination = destination
|
||||
self.includesFilterDrop = includesFilterDrop
|
||||
@@ -46,12 +46,14 @@ public struct EquipmentSettingsForm {
|
||||
}
|
||||
|
||||
// Note: These need to be in display order.
|
||||
public enum Field: Hashable, CaseIterable, FocusableField {
|
||||
public enum Field: Hashable, CaseIterable, FocusableField, Identifiable {
|
||||
case heatingCapacity
|
||||
case minimumStaticPressure
|
||||
case maximumStaticPressure
|
||||
case ratedStaticPressure
|
||||
case manufacturersIncludedFilterPressureDrop
|
||||
|
||||
public var id: Self { self }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,37 +185,9 @@ public struct EquipmentSettingsFormView: View {
|
||||
|
||||
Section {
|
||||
Grid(alignment: .leading, horizontalSpacing: 40) {
|
||||
GridRow {
|
||||
TextLabel("Minimum")
|
||||
textField(
|
||||
"Minimum Pressure",
|
||||
value: $store.sharedSettings.ratedStaticPressures.minimum,
|
||||
fractionLength: 2
|
||||
)
|
||||
.focused($focusedField, equals: .minimumStaticPressure)
|
||||
.decimalPad()
|
||||
}
|
||||
GridRow {
|
||||
TextLabel("Maximum")
|
||||
textField(
|
||||
"Maximum Pressure",
|
||||
value: $store.sharedSettings.ratedStaticPressures.maximum,
|
||||
fractionLength: 2
|
||||
)
|
||||
.focused($focusedField, equals: .maximumStaticPressure)
|
||||
.decimalPad()
|
||||
}
|
||||
GridRow {
|
||||
TextLabel("Rated")
|
||||
textField(
|
||||
"Rated Pressure",
|
||||
value: $store.sharedSettings.ratedStaticPressures.rated,
|
||||
fractionLength: 2
|
||||
)
|
||||
.focused($focusedField, equals: .ratedStaticPressure)
|
||||
.decimalPad()
|
||||
}
|
||||
ForEach(RatingsField.allCases, content: ratingsRow(for:))
|
||||
}
|
||||
.labeledContentStyle(.gridRow)
|
||||
} header: {
|
||||
header("Rated Static Pressure", infoView: .ratedStaticPressures)
|
||||
}
|
||||
@@ -231,8 +205,7 @@ public struct EquipmentSettingsFormView: View {
|
||||
Spacer()
|
||||
textField(
|
||||
"Filter Drop",
|
||||
value: $store.sharedSettings.manufacturersIncludedFilterPressureDrop,
|
||||
fractionLength: 2
|
||||
value: $store.sharedSettings.manufacturersIncludedFilterPressureDrop
|
||||
)
|
||||
.focused($focusedField, equals: .manufacturersIncludedFilterPressureDrop)
|
||||
.decimalPad()
|
||||
@@ -265,6 +238,27 @@ public struct EquipmentSettingsFormView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func ratingsRow(for ratingsField: RatingsField) -> some View {
|
||||
|
||||
func binding(for ratingsField: RatingsField) -> Binding<Double> {
|
||||
switch ratingsField {
|
||||
case .maximum:
|
||||
return $store.sharedSettings.ratedStaticPressures.maximum
|
||||
case .minimum:
|
||||
return $store.sharedSettings.ratedStaticPressures.minimum
|
||||
case .rated:
|
||||
return $store.sharedSettings.ratedStaticPressures.rated
|
||||
}
|
||||
}
|
||||
|
||||
return TextLabeledContent(ratingsField.label) {
|
||||
TextField(ratingsField.prompt, value: binding(for: ratingsField), fractionLength: 2)
|
||||
.decimalPad()
|
||||
.focused($focusedField, equals: ratingsField.field)
|
||||
.onSubmit { send(.submitField) }
|
||||
}
|
||||
}
|
||||
|
||||
private func header<Label: View>(
|
||||
infoView: EquipmentSettingsForm.InfoView,
|
||||
label: @escaping () -> Label
|
||||
@@ -283,20 +277,13 @@ public struct EquipmentSettingsFormView: View {
|
||||
header(infoView: infoView) { Text(title) }
|
||||
}
|
||||
|
||||
private func textField(
|
||||
_ title: String,
|
||||
value: Binding<Double>,
|
||||
fractionLength: Int = 2
|
||||
) -> some View {
|
||||
TextField(title, value: value, fractionLength: fractionLength, prompt: Text(title))
|
||||
}
|
||||
|
||||
private func textField(
|
||||
_ title: String,
|
||||
value: Binding<Double?>,
|
||||
fractionLength: Int = 2
|
||||
) -> some View {
|
||||
TextField(title, value: value, fractionLength: fractionLength, prompt: Text(title))
|
||||
.onSubmit { send(.submitField) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,12 +335,71 @@ fileprivate extension InfoViewFeature.State {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate enum RatingsField: String, Hashable, CaseIterable, Identifiable {
|
||||
case maximum
|
||||
case minimum
|
||||
case rated
|
||||
|
||||
var id: Self { self }
|
||||
|
||||
var field: EquipmentSettingsForm.State.Field {
|
||||
switch self {
|
||||
case .maximum: return .maximumStaticPressure
|
||||
case .minimum: return .minimumStaticPressure
|
||||
case .rated: return .ratedStaticPressure
|
||||
}
|
||||
}
|
||||
|
||||
var label: String { rawValue.capitalized }
|
||||
|
||||
var prompt: String { "\(label) Pressure" }
|
||||
}
|
||||
|
||||
//fileprivate extension Store where State == EquipmentSettingsForm.State {
|
||||
//
|
||||
//
|
||||
// func label(for ratingsField: RatingsField) -> String {
|
||||
// self.label(for: ratingsField.field)
|
||||
// }
|
||||
//
|
||||
// func prompt(for ratingsField: RatingsField) -> String {
|
||||
// self.prompt(for: ratingsField.field)
|
||||
// }
|
||||
//
|
||||
// func label(for field: EquipmentSettingsForm.State.Field) -> String {
|
||||
// switch field {
|
||||
// case .heatingCapacity:
|
||||
// return "Heating"
|
||||
// case .minimumStaticPressure:
|
||||
// return "Minimum"
|
||||
// case .maximumStaticPressure:
|
||||
// return "Maximum"
|
||||
// case .ratedStaticPressure:
|
||||
// return "Rated"
|
||||
// case .manufacturersIncludedFilterPressureDrop:
|
||||
// return "Filter Drop"
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// func prompt(for field: EquipmentSettingsForm.State.Field) -> String {
|
||||
// switch field {
|
||||
// case .heatingCapacity:
|
||||
// return "Heating Capacity"
|
||||
// case .minimumStaticPressure, .maximumStaticPressure, .ratedStaticPressure:
|
||||
// return "\(label(for: field)) Pressure"
|
||||
// case .manufacturersIncludedFilterPressureDrop:
|
||||
// return label(for: field)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
#Preview {
|
||||
NavigationStack {
|
||||
EquipmentSettingsFormView(
|
||||
store: Store(
|
||||
initialState: EquipmentSettingsForm.State(
|
||||
sharedSettings: Shared(SharedPressureEstimationSettings())
|
||||
sharedSettings: Shared(SharedPressureEstimationState())
|
||||
)
|
||||
) {
|
||||
EquipmentSettingsForm()._printChanges()
|
||||
|
||||
Reference in New Issue
Block a user