From 365ae0ef8cd917e3b63639db07d749539682e789 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sat, 16 Oct 2021 21:44:49 +0800 Subject: [PATCH] fix: FlowPane does not accept max-width setting. Closes #1109. --- .../hmcl/ui/construct/AdvancedListBox.java | 37 ++++++------------- .../hmcl/ui/construct/TwoLineListItem.java | 7 ++-- HMCL/src/main/resources/assets/css/root.css | 21 ++++------- 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java index 31f33061e..606043619 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java @@ -19,37 +19,26 @@ package org.jackhuang.hmcl.ui.construct; import javafx.collections.ObservableList; import javafx.scene.Node; -import javafx.scene.control.ScrollPane; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import org.jackhuang.hmcl.ui.FXUtils; import java.util.function.Consumer; -public class AdvancedListBox extends ScrollPane { - private final VBox container = new VBox(); +public class AdvancedListBox extends VBox { { - setContent(container); - - FXUtils.smoothScrolling(this); - - setFitToHeight(true); - setFitToWidth(true); - setHbarPolicy(ScrollBarPolicy.NEVER); - - container.getStyleClass().add("advanced-list-box-content"); + getStyleClass().add("advanced-list-box-content"); } public AdvancedListBox add(Node child) { if (child instanceof Pane || child instanceof AdvancedListItem) - container.getChildren().add(child); + getChildren().add(child); else { StackPane pane = new StackPane(); pane.getStyleClass().add("advanced-list-box-item"); pane.getChildren().setAll(child); - container.getChildren().add(pane); + getChildren().add(pane); } return this; } @@ -64,27 +53,27 @@ public class AdvancedListBox extends ScrollPane { public AdvancedListBox add(int index, Node child) { if (child instanceof Pane || child instanceof AdvancedListItem) - container.getChildren().add(index, child); + getChildren().add(index, child); else { StackPane pane = new StackPane(); pane.getStyleClass().add("advanced-list-box-item"); pane.getChildren().setAll(child); - container.getChildren().add(index, pane); + getChildren().add(index, pane); } return this; } public AdvancedListBox remove(Node child) { - container.getChildren().remove(indexOf(child)); + getChildren().remove(indexOf(child)); return this; } public int indexOf(Node child) { if (child instanceof Pane) { - return container.getChildren().indexOf(child); + return getChildren().indexOf(child); } else { - for (int i = 0; i < container.getChildren().size(); ++i) { - Node node = container.getChildren().get(i); + for (int i = 0; i < getChildren().size(); ++i) { + Node node = getChildren().get(i); if (node instanceof StackPane) { ObservableList list = ((StackPane) node).getChildren(); if (list.size() == 1 && list.get(0) == child) @@ -99,11 +88,7 @@ public class AdvancedListBox extends ScrollPane { return add(new ClassTitle(category)); } - public void setSpacing(double spacing) { - container.setSpacing(spacing); - } - public void clear() { - container.getChildren().clear(); + getChildren().clear(); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java index f309e83f1..51c98e159 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TwoLineListItem.java @@ -25,7 +25,6 @@ import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.control.Label; -import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import org.jackhuang.hmcl.ui.FXUtils; @@ -52,8 +51,8 @@ public class TwoLineListItem extends VBox { public TwoLineListItem() { setMouseTransparent(true); - FlowPane firstLine = new FlowPane(); - firstLine.setMaxWidth(Double.MAX_VALUE); + HBox firstLine = new HBox(); + firstLine.getStyleClass().add("first-line"); Label lblTitle = new Label(); lblTitle.getStyleClass().add("title"); @@ -63,7 +62,7 @@ public class TwoLineListItem extends VBox { Label tagLabel = new Label(); tagLabel.getStyleClass().add("tag"); tagLabel.setText(tag); - FlowPane.setMargin(tagLabel, new Insets(0, 8, 0, 0)); + HBox.setMargin(tagLabel, new Insets(0, 8, 0, 0)); return tagLabel; }); firstLineChildren = new AggregatedObservableList<>(); diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index 9624f8848..f8e84a7f1 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -151,7 +151,7 @@ -fx-padding: 0 0 0 10; } -.advanced-list-item > .rippler-container > .container > .two-line-list-item > FlowPane > .title { +.advanced-list-item > .rippler-container > .container > .two-line-list-item > .first-line > .title { -fx-font-size: 13; -fx-text-alignment: justify; } @@ -165,7 +165,7 @@ -fx-background-color: -fx-base-rippler-color; } -.advanced-list-item:selected > .rippler-container > .container > .two-line-list-item > FlowPane > .title { +.advanced-list-item:selected > .rippler-container > .container > .two-line-list-item > .first-line > .title { -fx-text-fill: -fx-base-color; -fx-font-weight: bold; } @@ -178,7 +178,7 @@ -fx-padding: 0 0 0 0; } -.profile-list-item > .rippler-container > BorderPane > .two-line-list-item > FlowPane > .title { +.profile-list-item > .rippler-container > BorderPane > .two-line-list-item > .first-line > .title { -fx-font-size: 13; } @@ -194,7 +194,7 @@ -fx-background-color: -fx-base-rippler-color; } -.profile-list-item:selected > .rippler-container > BorderPane > .two-line-list-item > FlowPane > .title { +.profile-list-item:selected > .rippler-container > BorderPane > .two-line-list-item > .first-line > .title { -fx-text-fill: -fx-base-color; -fx-font-weight: bold; } @@ -257,12 +257,7 @@ -fx-padding: 4 0 4 0; } -.two-line-list-item > HBox { - -fx-spacing: 8; - -fx-alignment: center-left; -} - -.two-line-list-item > FlowPane > .title { +.two-line-list-item > .first-line > .title { -fx-text-fill: #292929; -fx-font-size: 15px; -fx-padding: 0 8 0 0; @@ -274,7 +269,7 @@ -fx-font-size: 12px; } -.two-line-list-item > FlowPane > .tag { +.two-line-list-item > .first-line > .tag { -fx-text-fill: -fx-base-color; -fx-background-color: -fx-base-rippler-color; -fx-padding: 2; @@ -286,7 +281,7 @@ } -.two-line-item-second-large > FlowPane > .title { +.two-line-item-second-large > .first-line > .title { -fx-text-fill: rgba(0, 0, 0, 0.5); -fx-font-weight: normal; -fx-font-size: 12px; @@ -307,7 +302,7 @@ -fx-text-fill: white; } -.bubble > HBox > .two-line-list-item > FlowPane > .title, +.bubble > HBox > .two-line-list-item > .first-line > .title, .bubble > HBox > .two-line-list-item > HBox > .subtitle { -fx-text-fill: white; }