Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Eliminate unnecessary VStacks #196

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions Impedance Converter/Impedance Converter/CircuitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand All @@ -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")
}
}
}
Expand Down
84 changes: 40 additions & 44 deletions Impedance Converter/Impedance Converter/ImmittanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,27 @@ struct PolarParameterView<UnitType>: 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)
}
}
}
Expand Down Expand Up @@ -103,31 +101,29 @@ struct RectangularParameterView<UnitType: UnitWithPowerOfTen>: 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)
}
}
}
Expand Down