diff options
| author | sam-anthony <samanthony6@protonmail.com> | 2022-03-27 20:06:54 -0230 |
|---|---|---|
| committer | sam-anthony <samanthony6@protonmail.com> | 2022-03-27 20:06:54 -0230 |
| commit | 5bb9043aea41498c886aabdc7f1a32e40011dc4a (patch) | |
| tree | cd6b98b41a71cd641d6a8eea1b84286e6d4402ef /ui.go | |
| parent | 722ab14ee5c2bc70b880c4dec74d1b546ae144b2 (diff) | |
| download | volute-5bb9043aea41498c886aabdc7f1a32e40011dc4a.zip | |
build table widgets in a less ridiculous way
Diffstat (limited to 'ui.go')
| -rw-r--r-- | ui.go | 273 |
1 files changed, 116 insertions, 157 deletions
@@ -18,209 +18,168 @@ func engineDisplacementRow() *g.RowWidget { volumeUnitStrings()[selectedVolumeUnit], volumeUnitStrings(), &selectedVolumeUnit, - ). - OnChange(func() { - s := volumeUnitStrings()[selectedVolumeUnit] - u, err := volumeUnitFromString(s) - check(err) - displacement = volume{ - displacement.asUnit(u), - u, - } - }), + ).OnChange(func() { + s := volumeUnitStrings()[selectedVolumeUnit] + u, err := volumeUnitFromString(s) + check(err) + displacement = volume{ + displacement.asUnit(u), + u, + } + }), ) } func engineSpeedRow() *g.TableRowWidget { - return g.TableRow( + widgets := []g.Widget{ g.Label("Engine Speed"), g.Label("rpm"), - g.InputInt(&engineSpeed[0]).OnChange(func() { - engineMassFlowRate[0] = massFlowRateAt(0) - }), - g.InputInt(&engineSpeed[1]).OnChange(func() { - engineMassFlowRate[1] = massFlowRateAt(1) - }), - g.InputInt(&engineSpeed[2]).OnChange(func() { - engineMassFlowRate[2] = massFlowRateAt(2) - }), - g.InputInt(&engineSpeed[3]).OnChange(func() { - engineMassFlowRate[3] = massFlowRateAt(3) - }), - g.InputInt(&engineSpeed[4]).OnChange(func() { - engineMassFlowRate[4] = massFlowRateAt(4) - }), - g.InputInt(&engineSpeed[5]).OnChange(func() { - engineMassFlowRate[5] = massFlowRateAt(5) - }), - ) + } + for i := 0; i < numPoints; i++ { + i := i + widgets = append( + widgets, + g.InputInt(&engineSpeed[i]).OnChange(func() { + engineMassFlowRate[i] = massFlowRateAt(i) + }), + ) + } + return g.TableRow(widgets...) } func volumetricEfficiencyRow() *g.TableRowWidget { - return g.TableRow( + widgets := []g.Widget{ g.Label("Volumetric Efficiency"), g.Label("%"), - g.InputInt(&volumetricEfficiency[0]).OnChange(func() { - engineMassFlowRate[0] = massFlowRateAt(0) - }), - g.InputInt(&volumetricEfficiency[1]).OnChange(func() { - engineMassFlowRate[1] = massFlowRateAt(1) - }), - g.InputInt(&volumetricEfficiency[2]).OnChange(func() { - engineMassFlowRate[2] = massFlowRateAt(2) - }), - g.InputInt(&volumetricEfficiency[3]).OnChange(func() { - engineMassFlowRate[3] = massFlowRateAt(3) - }), - g.InputInt(&volumetricEfficiency[4]).OnChange(func() { - engineMassFlowRate[4] = massFlowRateAt(4) - }), - g.InputInt(&volumetricEfficiency[5]).OnChange(func() { - engineMassFlowRate[5] = massFlowRateAt(5) - }), - ) + } + for i := 0; i < numPoints; i++ { + i := i + widgets = append( + widgets, + g.InputInt(&volumetricEfficiency[i]).OnChange(func() { + engineMassFlowRate[i] = massFlowRateAt(i) + }), + ) + } + return g.TableRow(widgets...) } func intakeAirTemperatureRow() *g.TableRowWidget { - return g.TableRow( + widgets := []g.Widget{ g.Label("Intake Air Temperature"), g.Combo( "", temperatureUnitStrings()[selectedTemperatureUnit], temperatureUnitStrings(), &selectedTemperatureUnit, - ). - OnChange(func() { - s := temperatureUnitStrings()[selectedTemperatureUnit] - u, err := temperatureUnitFromString(s) - check(err) + ).OnChange(func() { + s := temperatureUnitStrings()[selectedTemperatureUnit] + u, err := temperatureUnitFromString(s) + check(err) - for i := range intakeAirTemperature { - t, err := intakeAirTemperature[i].asUnit(u) - check(err) - intakeAirTemperature[i] = temperature{t, u} - } - }), - g.InputFloat(&intakeAirTemperature[0].val).Format("%.2f"). - OnChange(func() { - engineMassFlowRate[0] = massFlowRateAt(0) - }), - g.InputFloat(&intakeAirTemperature[1].val).Format("%.2f"). - OnChange(func() { - engineMassFlowRate[1] = massFlowRateAt(1) - }), - g.InputFloat(&intakeAirTemperature[2].val).Format("%.2f"). - OnChange(func() { - engineMassFlowRate[2] = massFlowRateAt(2) - }), - g.InputFloat(&intakeAirTemperature[3].val).Format("%.2f"). - OnChange(func() { - engineMassFlowRate[3] = massFlowRateAt(3) - }), - g.InputFloat(&intakeAirTemperature[4].val).Format("%.2f"). - OnChange(func() { - engineMassFlowRate[4] = massFlowRateAt(4) - }), - g.InputFloat(&intakeAirTemperature[5].val).Format("%.2f"). - OnChange(func() { - engineMassFlowRate[5] = massFlowRateAt(5) - }), - ) + for i := range intakeAirTemperature { + t, err := intakeAirTemperature[i].asUnit(u) + check(err) + intakeAirTemperature[i] = temperature{t, u} + } + }), + } + for i := 0; i < numPoints; i++ { + i := i + widgets = append( + widgets, + g.InputFloat(&intakeAirTemperature[i].val). + Format("%.2f"). + OnChange(func() { + engineMassFlowRate[i] = massFlowRateAt(i) + }), + ) + } + return g.TableRow(widgets...) } func manifoldPressureRow() *g.TableRowWidget { - return g.TableRow( + widgets := []g.Widget{ g.Label("Manifold Absolute Pressure"), g.Combo( "", pressureUnitStrings()[selectedPressureUnit], pressureUnitStrings(), &selectedPressureUnit, - ). - OnChange(func() { - s := pressureUnitStrings()[selectedPressureUnit] - u, err := pressureUnitFromString(s) - check(err) + ).OnChange(func() { + s := pressureUnitStrings()[selectedPressureUnit] + u, err := pressureUnitFromString(s) + check(err) - for i := 0; i < numPoints; i++ { - manifoldPressure[i] = pressure{ - manifoldPressure[i].asUnit(u), - u, - } + for i := 0; i < numPoints; i++ { + manifoldPressure[i] = pressure{ + manifoldPressure[i].asUnit(u), + u, } - }), - g.InputFloat(&manifoldPressure[0].val).Format("%.2f"). - OnChange(func() { - pressureRatio[0] = pressureRatioAt(0) - engineMassFlowRate[0] = massFlowRateAt(0) - }), - g.InputFloat(&manifoldPressure[1].val).Format("%.2f"). - OnChange(func() { - pressureRatio[1] = pressureRatioAt(1) - engineMassFlowRate[1] = massFlowRateAt(1) - }), - g.InputFloat(&manifoldPressure[2].val).Format("%.2f"). - OnChange(func() { - pressureRatio[2] = pressureRatioAt(2) - engineMassFlowRate[2] = massFlowRateAt(2) - }), - g.InputFloat(&manifoldPressure[3].val).Format("%.2f"). - OnChange(func() { - pressureRatio[3] = pressureRatioAt(3) - engineMassFlowRate[3] = massFlowRateAt(3) - }), - g.InputFloat(&manifoldPressure[4].val).Format("%.2f"). - OnChange(func() { - pressureRatio[4] = pressureRatioAt(4) - engineMassFlowRate[4] = massFlowRateAt(4) - }), - g.InputFloat(&manifoldPressure[5].val).Format("%.2f"). - OnChange(func() { - pressureRatio[5] = pressureRatioAt(5) - engineMassFlowRate[5] = massFlowRateAt(5) - }), - ) + } + }), + } + for i := 0; i < numPoints; i++ { + i := i + widgets = append( + widgets, + g.InputFloat(&manifoldPressure[i].val).Format("%.2f"). + OnChange(func() { + pressureRatio[i] = pressureRatioAt(i) + engineMassFlowRate[i] = massFlowRateAt(i) + }), + ) + } + return g.TableRow(widgets...) } func pressureRatioRow() *g.TableRowWidget { - return g.TableRow( + widgets := []g.Widget{ g.Label("Pressure Ratio"), g.Label(""), - g.Label(strconv.FormatFloat(float64(pressureRatio[0]), 'f', 1, 32)), - g.Label(strconv.FormatFloat(float64(pressureRatio[1]), 'f', 1, 32)), - g.Label(strconv.FormatFloat(float64(pressureRatio[2]), 'f', 1, 32)), - g.Label(strconv.FormatFloat(float64(pressureRatio[3]), 'f', 1, 32)), - g.Label(strconv.FormatFloat(float64(pressureRatio[4]), 'f', 1, 32)), - g.Label(strconv.FormatFloat(float64(pressureRatio[5]), 'f', 1, 32)), - ) + } + for i := 0; i < numPoints; i++ { + pr := strconv.FormatFloat(float64(pressureRatio[i]), 'f', 1, 32) + widgets = append( + widgets, + g.Label(pr), + ) + } + return g.TableRow(widgets...) } func massFlowRateRow() *g.TableRowWidget { - return g.TableRow( + widgets := []g.Widget{ g.Label("Mass Flow Rate"), g.Combo( "", massFlowRateUnitStrings()[selectedMassFlowRateUnit], massFlowRateUnitStrings(), &selectedMassFlowRateUnit, - ). - OnChange(func() { - s := massFlowRateUnitStrings()[selectedMassFlowRateUnit] - u, err := massFlowRateUnitFromString(s) - check(err) + ).OnChange(func() { + s := massFlowRateUnitStrings()[selectedMassFlowRateUnit] + u, err := massFlowRateUnitFromString(s) + check(err) - for i := 0; i < numPoints; i++ { - engineMassFlowRate[i] = massFlowRate{ - engineMassFlowRate[i].asUnit(u), - u, - } + for i := 0; i < numPoints; i++ { + engineMassFlowRate[i] = massFlowRate{ + engineMassFlowRate[i].asUnit(u), + u, } - }), - g.Label(strconv.FormatFloat(float64(engineMassFlowRate[0].val), 'f', 3, 32)), - g.Label(strconv.FormatFloat(float64(engineMassFlowRate[1].val), 'f', 3, 32)), - g.Label(strconv.FormatFloat(float64(engineMassFlowRate[2].val), 'f', 3, 32)), - g.Label(strconv.FormatFloat(float64(engineMassFlowRate[3].val), 'f', 3, 32)), - g.Label(strconv.FormatFloat(float64(engineMassFlowRate[4].val), 'f', 3, 32)), - g.Label(strconv.FormatFloat(float64(engineMassFlowRate[5].val), 'f', 3, 32)), - ) + } + }), + } + for i := 0; i < numPoints; i++ { + mfr := strconv.FormatFloat( + float64(engineMassFlowRate[i].val), + 'f', + 3, + 32, + ) + widgets = append( + widgets, + g.Label(mfr), + ) + } + return g.TableRow(widgets...) } |