feat: clicking blanks area also toggles component list cell expansion.

This commit is contained in:
huanghongxun 2021-09-21 19:57:07 +08:00
parent c7a893b02d
commit ea844e03f9

View File

@ -29,10 +29,7 @@ import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.util.Duration; import javafx.util.Duration;
import org.jackhuang.hmcl.setting.Theme; import org.jackhuang.hmcl.setting.Theme;
@ -79,7 +76,9 @@ class ComponentListCell extends StackPane {
content.getStyleClass().remove("options-list"); content.getStyleClass().remove("options-list");
content.getStyleClass().add("options-sublist"); content.getStyleClass().add("options-sublist");
BorderPane groupNode = new BorderPane(); getStyleClass().add("no-padding");
VBox groupNode = new VBox();
Node expandIcon = SVG.expand(Theme.blackFillBinding(), 20, 20); Node expandIcon = SVG.expand(Theme.blackFillBinding(), 20, 20);
JFXButton expandButton = new JFXButton(); JFXButton expandButton = new JFXButton();
@ -87,6 +86,7 @@ class ComponentListCell extends StackPane {
expandButton.getStyleClass().add("options-list-item-expand-button"); expandButton.getStyleClass().add("options-list-item-expand-button");
VBox labelVBox = new VBox(); VBox labelVBox = new VBox();
labelVBox.setMouseTransparent(true);
labelVBox.setAlignment(Pos.CENTER_LEFT); labelVBox.setAlignment(Pos.CENTER_LEFT);
boolean overrideHeaderLeft = false; boolean overrideHeaderLeft = false;
@ -111,27 +111,30 @@ class ComponentListCell extends StackPane {
} }
} }
groupNode.setLeft(labelVBox); HBox header = new HBox();
header.setSpacing(16);
HBox right = new HBox(); header.getChildren().add(labelVBox);
right.setSpacing(16); header.setPadding(new Insets(10, 16, 10, 16));
right.setAlignment(Pos.CENTER_RIGHT); header.setAlignment(Pos.CENTER_LEFT);
HBox.setHgrow(labelVBox, Priority.ALWAYS);
if (list instanceof ComponentSublist) { if (list instanceof ComponentSublist) {
Node rightNode = ((ComponentSublist) list).getHeaderRight(); Node rightNode = ((ComponentSublist) list).getHeaderRight();
if (rightNode != null) if (rightNode != null)
right.getChildren().add(rightNode); header.getChildren().add(rightNode);
} }
right.getChildren().add(expandButton); header.getChildren().add(expandButton);
groupNode.setRight(right);
RipplerContainer headerRippler = new RipplerContainer(header);
groupNode.getChildren().add(headerRippler);
VBox container = new VBox(); VBox container = new VBox();
container.setPadding(new Insets(8, 0, 0, 0)); container.setPadding(new Insets(8, 16, 10, 16));
FXUtils.setLimitHeight(container, 0); FXUtils.setLimitHeight(container, 0);
FXUtils.setOverflowHidden(container); FXUtils.setOverflowHidden(container);
container.getChildren().setAll(content); container.getChildren().setAll(content);
groupNode.setBottom(container); groupNode.getChildren().add(container);
expandButton.setOnMouseClicked(e -> { Runnable onExpand = () -> {
if (expandAnimation != null && expandAnimation.getStatus() == Animation.Status.RUNNING) { if (expandAnimation != null && expandAnimation.getStatus() == Animation.Status.RUNNING) {
expandAnimation.stop(); expandAnimation.stop();
} }
@ -144,7 +147,7 @@ class ComponentListCell extends StackPane {
} }
Platform.runLater(() -> { Platform.runLater(() -> {
double newAnimatedHeight = content.prefHeight(-1) * (isExpanded() ? 1 : -1); double newAnimatedHeight = (content.prefHeight(-1) + 8 + 10) * (isExpanded() ? 1 : -1);
double newHeight = isExpanded() ? getHeight() + newAnimatedHeight : prefHeight(-1); double newHeight = isExpanded() ? getHeight() + newAnimatedHeight : prefHeight(-1);
double contentHeight = isExpanded() ? newAnimatedHeight : 0; double contentHeight = isExpanded() ? newAnimatedHeight : 0;
@ -163,13 +166,17 @@ class ComponentListCell extends StackPane {
expandAnimation.play(); expandAnimation.play();
}); });
}); };
headerRippler.setOnMouseClicked(e -> onExpand.run());
expandButton.setOnMouseClicked(e -> onExpand.run());
expandedProperty().addListener((a, b, newValue) -> expandedProperty().addListener((a, b, newValue) ->
expandIcon.setRotate(newValue ? 180 : 0)); expandIcon.setRotate(newValue ? 180 : 0));
getChildren().setAll(groupNode); getChildren().setAll(groupNode);
} else { } else {
getStyleClass().remove("no-padding");
getChildren().setAll(content); getChildren().setAll(content);
} }
} }