fix: FlowPane does not accept max-width setting. Closes #1109.

This commit is contained in:
huanghongxun
2021-10-16 21:44:49 +08:00
parent a6e593e3a1
commit 365ae0ef8c
3 changed files with 22 additions and 43 deletions

View File

@@ -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<Node> 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();
}
}

View File

@@ -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<>();

View File

@@ -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;
}