From b7bbebe222afb135a4476c63b0b9aa4f2ed478fa Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Sun, 18 Jan 2026 14:18:19 +0100 Subject: [PATCH 1/6] feat(client/scaling): initial implementation --- .../src/main/java/client/scenes/recipe/ScalableRecipeView.java | 2 -- commons/src/main/java/commons/Recipe.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java b/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java index aa80a97..1ebcc0d 100644 --- a/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java +++ b/client/src/main/java/client/scenes/recipe/ScalableRecipeView.java @@ -41,7 +41,6 @@ public class ScalableRecipeView { public double getScaledKcal() { return scaledKcal.get(); } - public DoubleProperty scaleProperty() { return scale; } @@ -53,7 +52,6 @@ public class ScalableRecipeView { public ObjectProperty recipeProperty() { return recipe; } - public SimpleDoubleProperty scaledKcalProperty() { return scaledKcal; } diff --git a/commons/src/main/java/commons/Recipe.java b/commons/src/main/java/commons/Recipe.java index 3828fde..f69ca35 100644 --- a/commons/src/main/java/commons/Recipe.java +++ b/commons/src/main/java/commons/Recipe.java @@ -206,4 +206,4 @@ public class Recipe { this.ingredients.stream().mapToDouble(RecipeIngredient::getBaseAmount).sum() * PER; } -} \ No newline at end of file +} From 23447a96d698d2119f46b36863f8251818fd6726 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Jan 2026 14:38:21 +0100 Subject: [PATCH 2/6] feat(commons/recipe): introduce weight sum calculations --- commons/src/main/java/commons/Recipe.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commons/src/main/java/commons/Recipe.java b/commons/src/main/java/commons/Recipe.java index f69ca35..e60fd30 100644 --- a/commons/src/main/java/commons/Recipe.java +++ b/commons/src/main/java/commons/Recipe.java @@ -203,7 +203,10 @@ public class Recipe { final double PER = 100; // Gram return this.ingredients.stream().mapToDouble(RecipeIngredient::getKcal).sum() / - this.ingredients.stream().mapToDouble(RecipeIngredient::getBaseAmount).sum() * PER; + weight() * PER; + } + public double weight() { + return this.ingredients.stream().mapToDouble(RecipeIngredient::getBaseAmount).sum(); } } From 8615187628005eed3138d387e18dfbff41510052 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Jan 2026 14:39:01 +0100 Subject: [PATCH 3/6] feat(client/serving): declare UI infrastructure and data deps for servings --- .../scenes/recipe/ScalableRecipeView.java | 37 +++++++++---------- .../scenes/recipe/RecipeDetailView.fxml | 2 + 2 files changed, 19 insertions(+), 20 deletions(-) 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 @@