diff --git a/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java b/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java index 1ebcc0d..e9192ab 100644 --- a/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java +++ b/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java @@ -4,15 +4,19 @@ import commons.Recipe; import javafx.beans.binding.Bindings; import javafx.beans.binding.ObjectBinding; import javafx.beans.property.DoubleProperty; +import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; public class ScalableRecipeView { private final ObjectProperty recipe = new SimpleObjectProperty<>(); private final ObjectProperty scaled = new SimpleObjectProperty<>(); private final DoubleProperty scale = new SimpleDoubleProperty(); - private final SimpleDoubleProperty scaledKcal = new SimpleDoubleProperty(); + private final DoubleProperty scaledKcal = new SimpleDoubleProperty(); + private final IntegerProperty servings = new SimpleIntegerProperty(); + private final DoubleProperty servingSize = new SimpleDoubleProperty(); public ScalableRecipeView( Recipe recipe, Double scale @@ -24,10 +28,10 @@ public class ScalableRecipeView { this.recipe, this.scale); this.scaled.bind(binding); this.scaledKcal.bind(Bindings.createDoubleBinding(() -> this.scaled.get().kcal(), this.scaled)); - } - - public double getScale() { - return scale.get(); + this.servingSize.bind(Bindings.createDoubleBinding( + () -> this.scaled.get().weight() * ( 1.0 / this.servings.get()), + this.servings) + ); } public Recipe getRecipe() { @@ -38,21 +42,14 @@ public class ScalableRecipeView { return scaled.get(); } - public double getScaledKcal() { - return scaledKcal.get(); - } - public DoubleProperty scaleProperty() { - return scale; - } - - public ObjectProperty scaledProperty() { - return scaled; - } - - public ObjectProperty recipeProperty() { - return recipe; - } - public SimpleDoubleProperty scaledKcalProperty() { + public DoubleProperty scaledKcalProperty() { return scaledKcal; } + + public IntegerProperty servingsProperty() { + return servings; + } + public DoubleProperty servingSizeProperty() { + return servingSize; + } } diff --git a/client/src/main/resources/client/scenes/recipe/RecipeDetailView.fxml b/client/src/main/resources/client/scenes/recipe/RecipeDetailView.fxml index 0ebb01b..56f108a 100644 --- a/client/src/main/resources/client/scenes/recipe/RecipeDetailView.fxml +++ b/client/src/main/resources/client/scenes/recipe/RecipeDetailView.fxml @@ -27,6 +27,7 @@