From c8dd95f822fc8b6bf9f4fc7229548c7e6f0f78c1 Mon Sep 17 00:00:00 2001 From: Mike Fikes Date: Tue, 23 Jan 2024 22:56:36 -0500 Subject: [PATCH] Eliminate unnecessary VStacks --- .../Impedance Converter/CircuitView.swift | 16 ++-- .../Impedance Converter/ImmittanceView.swift | 84 +++++++++---------- 2 files changed, 46 insertions(+), 54 deletions(-) diff --git a/Impedance Converter/Impedance Converter/CircuitView.swift b/Impedance Converter/Impedance Converter/CircuitView.swift index b984dbf..078039f 100644 --- a/Impedance Converter/Impedance Converter/CircuitView.swift +++ b/Impedance Converter/Impedance Converter/CircuitView.swift @@ -22,11 +22,9 @@ struct CapacitanceView: View { var body: some View { DisplayView { - VStack { - HStack { - UnitInputView(value: $viewModel.capacitance, unit: CapacitanceUnit.F, label: "C", description: "capacitance") - UnitInputView(value: $viewModel.dissipationFactor, unit: DissipationUnit.D, label: "D", description: "dissipation factor") - } + HStack { + UnitInputView(value: $viewModel.capacitance, unit: CapacitanceUnit.F, label: "C", description: "capacitance") + UnitInputView(value: $viewModel.dissipationFactor, unit: DissipationUnit.D, label: "D", description: "dissipation factor") } } } @@ -37,11 +35,9 @@ struct InductanceView: View { var body: some View { DisplayView { - VStack { - HStack { - UnitInputView(value: $viewModel.inductance, unit: InductanceUnit.H, label: "L", description: "inductance") - UnitInputView(value: $viewModel.qualityFactor, unit: QualityUnit.Q, label: "Q", description: "quality factor") - } + HStack { + UnitInputView(value: $viewModel.inductance, unit: InductanceUnit.H, label: "L", description: "inductance") + UnitInputView(value: $viewModel.qualityFactor, unit: QualityUnit.Q, label: "Q", description: "quality factor") } } } diff --git a/Impedance Converter/Impedance Converter/ImmittanceView.swift b/Impedance Converter/Impedance Converter/ImmittanceView.swift index a61e4c3..d3ba81e 100644 --- a/Impedance Converter/Impedance Converter/ImmittanceView.swift +++ b/Impedance Converter/Impedance Converter/ImmittanceView.swift @@ -12,29 +12,27 @@ struct PolarParameterView: View where UnitType: RawRepresentable, Unit var angleDescription: String var body: some View { - VStack { - HStack { - UnitInputView(value: Binding( - get: { self.complexValue.length }, - set: { - let phase = self.complexValue.phase.isNaN ? 0 : self.complexValue.phase - viewModel.setValueRecordingTrace(from: self.complexValue.length, to: $0) { - intermediateValue in - self.complexValue = Complex.init(length: intermediateValue, phase: phase) - } + HStack { + UnitInputView(value: Binding( + get: { self.complexValue.length }, + set: { + let phase = self.complexValue.phase.isNaN ? 0 : self.complexValue.phase + viewModel.setValueRecordingTrace(from: self.complexValue.length, to: $0) { + intermediateValue in + self.complexValue = Complex.init(length: intermediateValue, phase: phase) } - ), unit: magnitudeUnit, label: magnitudeLabel, description: magnitudeDescription) - - UnitInputView(value: Binding( - get: { Angle(radians: self.complexValue.phase).degrees }, - set: { - viewModel.setValueRecordingTrace(from: Angle(radians: self.complexValue.phase).degrees, to: $0) { - intermediateValue in - self.complexValue = Complex.init(length: self.complexValue.length, phase:Angle(degrees: intermediateValue).radians) - } + } + ), unit: magnitudeUnit, label: magnitudeLabel, description: magnitudeDescription) + + UnitInputView(value: Binding( + get: { Angle(radians: self.complexValue.phase).degrees }, + set: { + viewModel.setValueRecordingTrace(from: Angle(radians: self.complexValue.phase).degrees, to: $0) { + intermediateValue in + self.complexValue = Complex.init(length: self.complexValue.length, phase:Angle(degrees: intermediateValue).radians) } - ), unit: angleUnit, label: angleLabel, description: angleDescription, showNegationDecorator: true) - } + } + ), unit: angleUnit, label: angleLabel, description: angleDescription, showNegationDecorator: true) } } } @@ -103,31 +101,29 @@ struct RectangularParameterView: View { var imaginaryCanBeNegative: Bool var body: some View { - VStack { - HStack { - UnitInputView(value: Binding( - get: { self.complexValue.canonicalizedReal }, - set: { - let imaginary = self.complexValue.canonicalizedImaginary.isNaN ? 0 : self.complexValue.canonicalizedImaginary - viewModel.setValueRecordingTrace(from: self.complexValue.canonicalizedReal, to: $0) { - intermediateValue in - self.complexValue = Complex(intermediateValue, imaginary) - } + HStack { + UnitInputView(value: Binding( + get: { self.complexValue.canonicalizedReal }, + set: { + let imaginary = self.complexValue.canonicalizedImaginary.isNaN ? 0 : self.complexValue.canonicalizedImaginary + viewModel.setValueRecordingTrace(from: self.complexValue.canonicalizedReal, to: $0) { + intermediateValue in + self.complexValue = Complex(intermediateValue, imaginary) } - ), unit: realPartUnit, label: realPartLabel, description: realPartDescription, - showNegationDecorator: realCanBeNegative) - UnitInputView(value: Binding( - get: { self.complexValue.canonicalizedImaginary }, - set: { - let real = self.complexValue.canonicalizedReal.isNaN ? 0 : self.complexValue.canonicalizedReal - viewModel.setValueRecordingTrace(from: self.complexValue.canonicalizedImaginary, to: $0) { - intermediateValue in - self.complexValue = Complex(real, intermediateValue) - } + } + ), unit: realPartUnit, label: realPartLabel, description: realPartDescription, + showNegationDecorator: realCanBeNegative) + UnitInputView(value: Binding( + get: { self.complexValue.canonicalizedImaginary }, + set: { + let real = self.complexValue.canonicalizedReal.isNaN ? 0 : self.complexValue.canonicalizedReal + viewModel.setValueRecordingTrace(from: self.complexValue.canonicalizedImaginary, to: $0) { + intermediateValue in + self.complexValue = Complex(real, intermediateValue) } - ), unit: imaginaryPartUnit, label: imaginaryPartLabel, description: imaginaryPartDescription, - showNegationDecorator: imaginaryCanBeNegative) - } + } + ), unit: imaginaryPartUnit, label: imaginaryPartLabel, description: imaginaryPartDescription, + showNegationDecorator: imaginaryCanBeNegative) } } }