feat(client/serving): declare UI infrastructure and data deps for servings

This commit is contained in:
Zhongheng Liu 2026-01-19 14:39:01 +01:00
commit 8615187628
Signed by: steven
GPG key ID: F69B980899C1C09D
2 changed files with 19 additions and 20 deletions

View file

@ -4,15 +4,19 @@ import commons.Recipe;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.binding.ObjectBinding; import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
public class ScalableRecipeView { public class ScalableRecipeView {
private final ObjectProperty<Recipe> recipe = new SimpleObjectProperty<>(); private final ObjectProperty<Recipe> recipe = new SimpleObjectProperty<>();
private final ObjectProperty<Recipe> scaled = new SimpleObjectProperty<>(); private final ObjectProperty<Recipe> scaled = new SimpleObjectProperty<>();
private final DoubleProperty scale = new SimpleDoubleProperty(); 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( public ScalableRecipeView(
Recipe recipe, Recipe recipe,
Double scale Double scale
@ -24,10 +28,10 @@ public class ScalableRecipeView {
this.recipe, this.scale); this.recipe, this.scale);
this.scaled.bind(binding); this.scaled.bind(binding);
this.scaledKcal.bind(Bindings.createDoubleBinding(() -> this.scaled.get().kcal(), this.scaled)); this.scaledKcal.bind(Bindings.createDoubleBinding(() -> this.scaled.get().kcal(), this.scaled));
} this.servingSize.bind(Bindings.createDoubleBinding(
() -> this.scaled.get().weight() * ( 1.0 / this.servings.get()),
public double getScale() { this.servings)
return scale.get(); );
} }
public Recipe getRecipe() { public Recipe getRecipe() {
@ -38,21 +42,14 @@ public class ScalableRecipeView {
return scaled.get(); return scaled.get();
} }
public double getScaledKcal() { public DoubleProperty scaledKcalProperty() {
return scaledKcal.get();
}
public DoubleProperty scaleProperty() {
return scale;
}
public ObjectProperty<Recipe> scaledProperty() {
return scaled;
}
public ObjectProperty<Recipe> recipeProperty() {
return recipe;
}
public SimpleDoubleProperty scaledKcalProperty() {
return scaledKcal; return scaledKcal;
} }
public IntegerProperty servingsProperty() {
return servings;
}
public DoubleProperty servingSizeProperty() {
return servingSize;
}
} }

View file

@ -27,6 +27,7 @@
<Button fx:id="favouriteButton" onAction="#toggleFavourite" text="☆" /> <Button fx:id="favouriteButton" onAction="#toggleFavourite" text="☆" />
<Label>Scale: </Label> <Label>Scale: </Label>
<Spinner fx:id="scaleSpinner" /> <Spinner fx:id="scaleSpinner" />
<Spinner fx:id="servingsSpinner" />
</HBox> </HBox>
<ComboBox fx:id="langSelector" onAction="#changeLanguage" /> <ComboBox fx:id="langSelector" onAction="#changeLanguage" />
@ -37,5 +38,6 @@
<!-- Preparation --> <!-- Preparation -->
<fx:include source="RecipeStepList.fxml" fx:id="stepList" <fx:include source="RecipeStepList.fxml" fx:id="stepList"
VBox.vgrow="ALWAYS" maxWidth="Infinity" /> VBox.vgrow="ALWAYS" maxWidth="Infinity" />
<Label fx:id="inferredServeSizeLabel" />
<Label fx:id="inferredKcalLabel" /> <Label fx:id="inferredKcalLabel" />
</VBox> </VBox>