From a54e919ed5d4b049447b44acde185d0aa350cd1c Mon Sep 17 00:00:00 2001
From: pawelsa
Date: Mon, 25 May 2026 22:00:13 +0200
Subject: [PATCH] feat: Style and layout enchancements
---
.../components/elements/RecieptComponent.java | 10 +-
.../elements/SearchBarComponent.java | 43 ++----
.../components/elements/ShareComponent.java | 5 +-
.../elements/TransactionComponent.java | 5 +-
.../idatt/view/components/ui/UIFactory.java | 124 ++++++++++++------
.../ntnu/idi/idatt/view/util/CssUtils.java | 2 +
.../idi/idatt/view/util/ResourceUtils.java | 2 -
src/main/resources/themes/default.css | 68 +++++-----
8 files changed, 145 insertions(+), 114 deletions(-)
diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java
index 16e39d4..8ada10f 100644
--- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java
+++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java
@@ -41,7 +41,9 @@ public RecieptComponent(Transaction transaction) {
CssUtils.apply(title, CssUtils.BIG_TEXT_32);
Label operation = new Label();
- String operationString = "Transaction type: %s, week: %d";
+ String operationString = "Transaction type: %s";
+
+ Label week = new Label(String.format("Week: %s", transaction.getWeek()));
Label shareName = new Label(String.format("Share: %s", transaction.getShare().getStock().toString()));
Label shareAmount = new Label(String.format("Amount: %.3f", transaction.getShare().getQuantity()));
@@ -60,14 +62,14 @@ public RecieptComponent(Transaction transaction) {
Label profits = new Label();
- List
*
- * @param placeholder - Placeholder for searchbar.
- * @param onSearchQuery - Input functional interface of searchbar.
+ * @param placeholder - Placeholder for searchbar.
+ * @param searchQuery - Functional interface of searchbar input property.
* @return header element.
*/
- public static Parent createHeader(String placeholder, Consumer onSearchQuery) {
- return createDefaultHeader(placeholder, onSearchQuery);
+ public static Parent createHeader(String placeholder, Consumer searchQuery) {
+ return createDefaultHeader(placeholder, searchQuery);
}
/**
@@ -55,13 +61,14 @@ public static Parent createHeader(String placeholder, Consumer onSearchQ
* Creates a header with searchbar with sorting ability.
*
*
- * @param placeholder - Placeholder for searchbar.
- * @param onSearchQuery - Input functional interface of searchbar.
- * @param sortItems - List of available sorting labels.
- * @param sortHandlers - List of functional interfaces to react to the items.
+ * @param placeholder - Placeholder for searchbar.
+ * @param searchQuery - Functional interface of searchbar input property.
+ * @param sortItems - List of available sorting labels.
+ * @param sortHandlers - List of functional interfaces to react to the items.
* @return header element.
*/
- public static Parent createHeader(String placeholder, Consumer onSearchQuery, List sortItems,
+ public static Parent createHeader(String placeholder, Consumer searchQuery,
+ List sortItems,
ActionEventHandler... sortHandlers) {
if (sortItems.size() != sortHandlers.length) {
@@ -70,7 +77,7 @@ public static Parent createHeader(String placeholder, Consumer onSearchQ
}
MenuButton menu = new MenuButton("Sort by..");
- HBox.setMargin(menu, new Insets(20));
+ menu.getStyleClass().add("menu-button");
sortItems.forEach(item -> {
MenuItem m = new MenuItem(item);
@@ -78,7 +85,7 @@ public static Parent createHeader(String placeholder, Consumer onSearchQ
menu.getItems().add(m);
});
- return createDefaultHeader(placeholder, onSearchQuery, menu);
+ return createDefaultHeader(placeholder, searchQuery, menu);
}
/**
@@ -88,12 +95,14 @@ public static Parent createHeader(String placeholder, Consumer onSearchQ
* This method is used for creating all headers through the public wrappers.
*
*
- * @param placeholder - Placeholder for searchbar.
- * @param onSearchQuery - Input functional interface of searchbar.
- * @param addons - Parent objects to add to the left site header
+ * @param placeholder - Placeholder for searchbar.
+ * @param searchQuery - Functional interface of searchbar input property.
+ * @param addons - Parent objects to add to the left site header
* @return header element.
*/
- private static Parent createDefaultHeader(String placeholder, Consumer onSearchQuery, Parent... addons) {
+ private static Parent createDefaultHeader(String placeholder, Consumer searchQuery,
+ Parent... addons) {
+
SearchBarComponent bar = new SearchBarComponent(placeholder);
HBox.setMargin(bar, new Insets(20));
@@ -101,13 +110,17 @@ private static Parent createDefaultHeader(String placeholder, Consumer o
UICompositor header = new UICompositor.Builder()
.parent(new HBox())
.growWithAlignment(Pos.CENTER)
+ .properties(parent -> parent.setPadding(new Insets(0, 10, 0, 10)))
.addAllContent(addons)
.filler()
+ .filler()
.addContent(bar)
.filler()
+ .filler()
+ .filler()
.build();
- bar.onSearchQuery(() -> onSearchQuery.accept(bar.getQuery())); // Remake?
+ searchQuery.accept(bar.getQuery());
return header.makeUI();
}
@@ -171,25 +184,43 @@ private static Parent createDefaultNavigation(Label titleLabel, List but
buttons.add(new Button(buttonLabel));
}
buttons.forEach(b -> {
- CssUtils.apply(b, CssUtils.MED_TEXT_16);
b.setOnAction((e) -> handlers[buttons.indexOf(b)].handle());
});
UICompositor.Builder navigationBuilder = new UICompositor.Builder()
- .parent(new VBox())
+ .parent(new VBox(10))
.growWithAlignment(Pos.CENTER)
+ .properties(nav -> nav.setPadding(new Insets(40)))
.addContent(titleLabel);
buttons.forEach(b -> navigationBuilder.addContent(b));
- navigationBuilder.filler();
+ navigationBuilder
+ .filler();
if (!SceneFactory.isFinal()) {
- Button previous = new Button("Previous");
+ Button previous = new Button("Previous Page");
previous.setOnAction((e) -> SceneFactory.goBack());
navigationBuilder.addContent(previous);
}
+ Button progress = new Button("Advance to next week");
+ progress.setOnAction((e) -> {
+ UserSession.getInstance().getExchange().advance();
+ UserSession.getInstance().updateGameState();
+ SceneFactory.reloadCurrent();
+ });
+
+ navigationBuilder.addContent(progress);
+
+ // Styles and properties of childs
+ navigationBuilder.properties(nav -> nav.getChildren()
+ .filtered(c -> !(c instanceof Label))
+ .forEach(c -> ((Region) c).setMaxWidth(Double.MAX_VALUE)));
+ navigationBuilder.properties(nav -> nav.getChildren()
+ .filtered(c -> c instanceof Button)
+ .forEach(c -> c.getStyleClass().add("button-outlined")));
+
UICompositor navigation = navigationBuilder.build();
return navigation.makeUI();
@@ -213,35 +244,33 @@ public static Parent createMenu(String title, List buttonLables, ActionE
System.out.println("Failed to build menu!");
}
- IconComponent menuIcon = new IconComponent(ResourceUtils.MENU_ICON, title, 60);
- CssUtils.apply(menuIcon, CssUtils.BIG_TEXT_32);
+ Label titleLabel = new Label(title);
+ CssUtils.apply(titleLabel, CssUtils.BIG_TEXT_32);
ArrayList