From 0ccb352b7eb76f08e2d04abbcf7583f82907d782 Mon Sep 17 00:00:00 2001 From: Glavo Date: Thu, 22 Jan 2026 22:26:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=20ComponentListCell=20(#5278?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/ui/construct/ComponentListCell.java | 54 ++----------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java index 67f94a921..20503523c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java @@ -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); - } }