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.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> recipe = new SimpleObjectProperty<>();
private final ObjectProperty<Recipe> 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<Recipe> scaledProperty() {
return scaled;
}
public ObjectProperty<Recipe> recipeProperty() {
return recipe;
}
public SimpleDoubleProperty scaledKcalProperty() {
public DoubleProperty scaledKcalProperty() {
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="☆" />
<Label>Scale: </Label>
<Spinner fx:id="scaleSpinner" />
<Spinner fx:id="servingsSpinner" />
</HBox>
<ComboBox fx:id="langSelector" onAction="#changeLanguage" />
@ -37,5 +38,6 @@
<!-- Preparation -->
<fx:include source="RecipeStepList.fxml" fx:id="stepList"
VBox.vgrow="ALWAYS" maxWidth="Infinity" />
<Label fx:id="inferredServeSizeLabel" />
<Label fx:id="inferredKcalLabel" />
</VBox>