feat(client/main): append main UI logic to handle serving size rendering
This commit is contained in:
parent
8615187628
commit
6931367145
1 changed files with 15 additions and 1 deletions
|
|
@ -49,6 +49,8 @@ public class RecipeDetailCtrl implements LocaleAware {
|
||||||
|
|
||||||
public Spinner<Double> scaleSpinner;
|
public Spinner<Double> scaleSpinner;
|
||||||
public Label inferredKcalLabel;
|
public Label inferredKcalLabel;
|
||||||
|
public Spinner<Integer> servingsSpinner;
|
||||||
|
public Label inferredServeSizeLabel;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private IngredientListCtrl ingredientListController;
|
private IngredientListCtrl ingredientListController;
|
||||||
|
|
@ -157,7 +159,7 @@ public class RecipeDetailCtrl implements LocaleAware {
|
||||||
|
|
||||||
// If there is a scale
|
// If there is a scale
|
||||||
// Prevents issues from first startup
|
// Prevents issues from first startup
|
||||||
if (scaleSpinner.getValue() != null) {
|
if (scaleSpinner.getValue() != null && servingsSpinner.getValue() != null) {
|
||||||
Double scale = scaleSpinner.getValue();
|
Double scale = scaleSpinner.getValue();
|
||||||
// see impl. creates a scaled context for the recipe such that its non-scaled value is kept as a reference.
|
// see impl. creates a scaled context for the recipe such that its non-scaled value is kept as a reference.
|
||||||
this.recipeView = new ScalableRecipeView(recipe, scale);
|
this.recipeView = new ScalableRecipeView(recipe, scale);
|
||||||
|
|
@ -167,6 +169,10 @@ public class RecipeDetailCtrl implements LocaleAware {
|
||||||
Double.isNaN(this.recipeView.scaledKcalProperty().get()) ?
|
Double.isNaN(this.recipeView.scaledKcalProperty().get()) ?
|
||||||
0.0 : this.recipeView.scaledKcalProperty().get())
|
0.0 : this.recipeView.scaledKcalProperty().get())
|
||||||
, this.recipeView.scaledKcalProperty()));
|
, this.recipeView.scaledKcalProperty()));
|
||||||
|
recipeView.servingsProperty().set(servingsSpinner.getValue());
|
||||||
|
inferredServeSizeLabel.textProperty().bind(Bindings.createStringBinding(
|
||||||
|
() -> String.format("Inferred size per serving: %.1f g", recipeView.servingSizeProperty().get()),
|
||||||
|
recipeView.servingSizeProperty()));
|
||||||
// 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());
|
||||||
this.stepListController.refetchFromRecipe(this.recipeView.getScaled());
|
this.stepListController.refetchFromRecipe(this.recipeView.getScaled());
|
||||||
|
|
@ -402,6 +408,14 @@ public class RecipeDetailCtrl implements LocaleAware {
|
||||||
// triggers a UI update each time the spinner changes to a different value.
|
// triggers a UI update each time the spinner changes to a different value.
|
||||||
setCurrentlyViewedRecipe(recipe);
|
setCurrentlyViewedRecipe(recipe);
|
||||||
});
|
});
|
||||||
|
servingsSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 1));
|
||||||
|
servingsSpinner.setEditable(true);
|
||||||
|
servingsSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if (newValue == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCurrentlyViewedRecipe(recipe);
|
||||||
|
});
|
||||||
langSelector.getItems().addAll("en", "nl", "pl", "tok");
|
langSelector.getItems().addAll("en", "nl", "pl", "tok");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue