From 5942250f11e6438f1d89665d4881172d883c8fd5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Sat, 17 Jan 2026 13:37:24 +0100 Subject: [PATCH] docs: add notes to makeMenuItems --- .../scenes/recipe/IngredientListCell.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/client/scenes/recipe/IngredientListCell.java b/client/src/main/java/client/scenes/recipe/IngredientListCell.java index f29dd8d..a96c5fc 100644 --- a/client/src/main/java/client/scenes/recipe/IngredientListCell.java +++ b/client/src/main/java/client/scenes/recipe/IngredientListCell.java @@ -82,6 +82,18 @@ public class IngredientListCell extends OrderedEditableListCellmenu reference. + * @param menu The MenuButton to add items to. + * @param items The items to add to the dropdown menu. + * @param labelMapper A function that outputs a string from the object to display on the label. + * @param onSelect Callback that triggers upon selection. + * @param container Parent container of the menu. + * Required since the UI logic needs to append a field to the end of the HBox upon selection + * @param The type this menu concerns itself with. + */ private void makeMenuItems( MenuButton menu, Iterable items, @@ -90,15 +102,21 @@ public class IngredientListCell extends OrderedEditableListCell { - menu.setText("New Ingredient"); - selectedIngredient.setValue(null); + menu.setText("New Ingredient"); // otherwise the text label on menu refuses to update + selectedIngredient.setValue(null); // indicate null to signal a new ingredient creation logger.info("Making new ingredient"); // TODO printError() integration TextField newIngredientNameInput = makeNewIngredientNameField(selectedIngredient::set); container.getChildren().add(newIngredientNameInput); }); + + // Puts the add ingredient button and a separator on top of the dropdown menu. menu.getItems().addAll(newIngredientItem, new SeparatorMenuItem()); + + // Iterates over the list of items and applies the label and onSelect handlers. for (T item : items) { MenuItem mi = new MenuItem(); mi.setText(labelMapper.apply(item)); @@ -127,8 +145,6 @@ public class IngredientListCell extends OrderedEditableListCell