fix: no more NaN

This commit is contained in:
Zhongheng Liu 2026-01-21 14:58:06 +01:00
commit 72f29467bd
Signed by: steven
GPG key ID: F69B980899C1C09D

View file

@ -163,7 +163,9 @@ public class RecipeDetailCtrl implements LocaleAware {
this.recipeView = new ScalableRecipeView(recipe, scale); this.recipeView = new ScalableRecipeView(recipe, scale);
// TODO i18n // TODO i18n
inferredKcalLabel.textProperty().bind(Bindings.createStringBinding(() -> inferredKcalLabel.textProperty().bind(Bindings.createStringBinding(() ->
String.format("Inferred %.1f kcal/100g for this recipe", this.recipeView.scaledKcalProperty().get()) String.format("Inferred %.1f kcal/100g for this recipe",
Double.isNaN(this.recipeView.scaledKcalProperty().get()) ?
0.0 : this.recipeView.scaledKcalProperty().get())
, this.recipeView.scaledKcalProperty())); , this.recipeView.scaledKcalProperty()));
// expose the scaled view to list controllers // expose the scaled view to list controllers
this.ingredientListController.refetchFromRecipe(this.recipeView.getScaled()); this.ingredientListController.refetchFromRecipe(this.recipeView.getScaled());
@ -391,7 +393,7 @@ public class RecipeDetailCtrl implements LocaleAware {
public void initializeComponents() { public void initializeComponents() {
initStepsIngredientsList(); initStepsIngredientsList();
// creates a new scale spinner with an arbitrary max scale // creates a new scale spinner with an arbitrary max scale
scaleSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, Double.MAX_VALUE, 1)); scaleSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(1, Double.MAX_VALUE, 1));
scaleSpinner.setEditable(true); scaleSpinner.setEditable(true);
scaleSpinner.valueProperty().addListener((observable, oldValue, newValue) -> { scaleSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == null) { if (newValue == null) {