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