From dbd07b5a2f548fc59272263c13361614ee526fc2 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Fri, 28 Oct 2022 01:56:38 +0800 Subject: [PATCH 01/15] Show overflow when items have many tags --- src/main/java/seedu/foodrem/ui/ItemCard.java | 10 +++++++++- src/main/resources/view/FoodRem.css | 5 +++++ src/main/resources/view/ItemListCard.fxml | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/foodrem/ui/ItemCard.java b/src/main/java/seedu/foodrem/ui/ItemCard.java index 079a5242b86..a5cd9ed65f8 100644 --- a/src/main/java/seedu/foodrem/ui/ItemCard.java +++ b/src/main/java/seedu/foodrem/ui/ItemCard.java @@ -16,6 +16,8 @@ * A UI component that displays information of a {@code Item}. */ public class ItemCard extends UiPart { + private static final int TAGS_LIMIT = 5; + /** * Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX. * As a consequence, UI elements' variable names cannot be set to such keywords @@ -49,8 +51,14 @@ public ItemCard(Item item, int displayedIndex) { quantity.setText(ItemView.buildItemQuantityAndUnitStringFrom(item)); quantity.setTextAlignment(TextAlignment.RIGHT); - item.getTagSet().stream().sorted(Comparator.comparing(Tag::getName)) + final int size = item.getTagSet().size(); + item.getTagSet().stream().sorted(Comparator.comparing(Tag::getName)).limit(TAGS_LIMIT) .forEach(tag -> tags.getChildren().add(buildTagNodeFrom(tag.getName()))); + if (size > TAGS_LIMIT) { + final Label overflowLabel = new Label(String.format("+%d more...", size - TAGS_LIMIT)); + overflowLabel.getStyleClass().add("tags-overflow-label"); + tags.getChildren().add(overflowLabel); + } } private static Node buildTagNodeFrom(String tagName) { diff --git a/src/main/resources/view/FoodRem.css b/src/main/resources/view/FoodRem.css index 0124f2358bc..ebc9b329c50 100644 --- a/src/main/resources/view/FoodRem.css +++ b/src/main/resources/view/FoodRem.css @@ -129,3 +129,8 @@ .list-view .list-cell:odd { -fx-background-radius: 8; } + +.tags-overflow-label { + -fx-font-size: 8pt; + -fx-font-fill: gray; +} diff --git a/src/main/resources/view/ItemListCard.fxml b/src/main/resources/view/ItemListCard.fxml index 5b652b1aae5..6bbaad7eb3b 100644 --- a/src/main/resources/view/ItemListCard.fxml +++ b/src/main/resources/view/ItemListCard.fxml @@ -24,6 +24,6 @@