feat(client/serving): declare UI infrastructure and data deps for servings
This commit is contained in:
parent
23447a96d6
commit
8615187628
2 changed files with 19 additions and 20 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue