清理 ComponentListCell (#5278)

This commit is contained in:
Glavo
2026-01-22 22:26:42 +08:00
committed by GitHub
parent 6d8add6d54
commit 0ccb352b7e

View File

@@ -19,8 +19,6 @@ package org.jackhuang.hmcl.ui.construct;
import javafx.animation.*;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
@@ -28,7 +26,6 @@ import javafx.scene.control.Label;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
import org.jackhuang.hmcl.theme.Themes;
import org.jackhuang.hmcl.ui.FXUtils;
@@ -42,8 +39,7 @@ import org.jackhuang.hmcl.ui.animation.Motion;
final class ComponentListCell extends StackPane {
private final Node content;
private Animation expandAnimation;
private Rectangle clipRect;
private final BooleanProperty expanded = new SimpleBooleanProperty(this, "expanded", false);
private boolean expanded = false;
ComponentListCell(Node content) {
this.content = content;
@@ -51,25 +47,6 @@ final class ComponentListCell extends StackPane {
updateLayout();
}
private void updateClip(double newHeight) {
if (clipRect != null)
clipRect.setHeight(newHeight);
}
@Override
protected void layoutChildren() {
super.layoutChildren();
if (clipRect == null)
clipRect = new Rectangle(0, 0, getWidth(), getHeight());
else {
clipRect.setX(0);
clipRect.setY(0);
clipRect.setHeight(getHeight());
clipRect.setWidth(getWidth());
}
}
private void updateLayout() {
if (content instanceof ComponentList list) {
content.getStyleClass().remove("options-list");
@@ -147,8 +124,8 @@ final class ComponentListCell extends StackPane {
expandAnimation.stop();
}
boolean expanded = !isExpanded();
setExpanded(expanded);
boolean expanded = !this.expanded;
this.expanded = expanded;
if (expanded) {
list.doLazyInit();
list.layout();
@@ -157,14 +134,9 @@ final class ComponentListCell extends StackPane {
Platform.runLater(() -> {
// FIXME: ComponentSubList without padding must have a 4 pixel padding for displaying a border radius.
double newAnimatedHeight = (list.prefHeight(list.getWidth()) + (hasPadding ? 8 + 10 : 4)) * (expanded ? 1 : -1);
double newHeight = expanded ? getHeight() + newAnimatedHeight : prefHeight(list.getWidth());
double contentHeight = expanded ? newAnimatedHeight : 0;
double targetRotate = expanded ? -180 : 0;
if (expanded) {
updateClip(newHeight);
}
if (AnimationUtils.isAnimationEnabled()) {
double currentRotate = expandIcon.getRotate();
Duration duration = Motion.LONG2.multiply(Math.abs(currentRotate - targetRotate) / 180.0);
@@ -177,19 +149,11 @@ final class ComponentListCell extends StackPane {
new KeyValue(expandIcon.rotateProperty(), targetRotate, interpolator))
);
if (!expanded) {
expandAnimation.setOnFinished(e2 -> updateClip(newHeight));
}
expandAnimation.play();
} else {
container.setMinHeight(contentHeight);
container.setMaxHeight(contentHeight);
expandIcon.setRotate(targetRotate);
if (!expanded) {
updateClip(newHeight);
}
}
});
});
@@ -200,16 +164,4 @@ final class ComponentListCell extends StackPane {
getChildren().setAll(content);
}
}
public boolean isExpanded() {
return expanded.get();
}
public BooleanProperty expandedProperty() {
return expanded;
}
public void setExpanded(boolean expanded) {
this.expanded.set(expanded);
}
}