From d3b91d439ca36a1d1ecbc7c105f37dae5278bf8d Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 3 Nov 2026 11:10:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=20Tab=20=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E9=80=89=E6=8B=A9=E5=8A=A8=E7=94=BB=E6=96=B9?= =?UTF-8?q?=E5=90=91=20(#7172)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/animation/ContainerAnimations.java | 68 ++++++++++++++----- .../hmcl/ui/animation/TransitionPane.java | 3 +- .../hmcl/ui/construct/TabController.java | 6 +- .../terracotta/TerracottaControllerPage.java | 4 +- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/ContainerAnimations.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/ContainerAnimations.java index bb252f00f1..e5621b0625 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/ContainerAnimations.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/ContainerAnimations.java @@ -7,7 +7,10 @@ import javafx.scene.Node; import javafx.scene.layout.Pane; import javafx.util.Duration; import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage; +import org.jetbrains.annotations.NotNullByDefault; +/// Supplies reusable page replacement animations. +@NotNullByDefault public enum ContainerAnimations implements TransitionPane.AnimationProducer { NONE { @Override @@ -170,28 +173,36 @@ public enum ContainerAnimations implements TransitionPane.AnimationProducer { } }, - /// Imitates the animation when switching tabs in the Windows 11 Settings interface - SLIDE_UP_FADE_IN { + /// Preserves the original slide-up and fade-in transition. + TAB_UP { + /// Creates the original slide-and-fade timing along the selected vertical direction. @Override - public Timeline animate( - Pane container, Node previousNode, Node nextNode, - Duration duration, Interpolator interpolator) { - double offset = container.getHeight() > 0 ? container.getHeight() * 0.2 : 50; - return new Timeline( - new KeyFrame(Duration.ZERO, - new KeyValue(previousNode.translateYProperty(), 0, interpolator), - new KeyValue(previousNode.opacityProperty(), 1, interpolator), - new KeyValue(nextNode.opacityProperty(), 0, interpolator), - new KeyValue(nextNode.translateYProperty(), offset, interpolator)), - new KeyFrame(duration.multiply(0.5), - new KeyValue(previousNode.opacityProperty(), 0, interpolator)), - new KeyFrame(duration, - new KeyValue(nextNode.opacityProperty(), 1, interpolator), - new KeyValue(nextNode.translateYProperty(), 0, interpolator)) - ); + public Timeline animate(Pane container, Node previousNode, Node nextNode, + Duration duration, Interpolator interpolator) { + return animateTab(container, previousNode, nextNode, duration, interpolator, 1); + } + + /// Returns the reverse tab transition. + @Override + public TransitionPane.AnimationProducer opposite() { + return TAB_DOWN; } }, + /// Mirrors the original slide-up and fade-in transition vertically. + TAB_DOWN { + /// Creates the original slide-and-fade timing along the selected vertical direction. + @Override + public Timeline animate(Pane container, Node previousNode, Node nextNode, + Duration duration, Interpolator interpolator) { + return animateTab(container, previousNode, nextNode, duration, interpolator, -1); + } + /// Returns the reverse tab transition. + @Override + public TransitionPane.AnimationProducer opposite() { + return TAB_UP; + } + }, NAVIGATION { /// Also clears the horizontal offsets of the target page's navigation panels. @Override @@ -246,4 +257,25 @@ public enum ContainerAnimations implements TransitionPane.AnimationProducer { } }, ; + + /// Preserves the original slide-up fade timing, varying only the vertical direction. + /// The previous page stays still and fades out halfway through the incoming page's motion. + private static Timeline animateTab(Pane container, Node previousNode, Node nextNode, Duration duration, + Interpolator interpolator, double direction) { + double extent = container.getHeight(); + double offset = (extent > 0 ? extent * 0.2 : 50) * direction; + var previousTranslation = previousNode.translateYProperty(); + var nextTranslation = nextNode.translateYProperty(); + return new Timeline( + new KeyFrame(Duration.ZERO, + new KeyValue(previousTranslation, 0, interpolator), + new KeyValue(previousNode.opacityProperty(), 1, interpolator), + new KeyValue(nextNode.opacityProperty(), 0, interpolator), + new KeyValue(nextTranslation, offset, interpolator)), + new KeyFrame(duration.multiply(0.5), + new KeyValue(previousNode.opacityProperty(), 0, interpolator)), + new KeyFrame(duration, + new KeyValue(nextNode.opacityProperty(), 1, interpolator), + new KeyValue(nextTranslation, 0, interpolator))); + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java index 1afd298885..357e78dadc 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/animation/TransitionPane.java @@ -349,7 +349,8 @@ public class TransitionPane extends StackPane { /// or `null` to not cache it. default @Nullable CacheHint getCacheHint(AnimationProducer animationProducer) { // https://github.com/HMCL-dev/HMCL/issues/4789 - return animationProducer == ContainerAnimations.SLIDE_UP_FADE_IN ? CacheHint.SPEED : null; + return animationProducer == ContainerAnimations.TAB_UP + || animationProducer == ContainerAnimations.TAB_DOWN ? CacheHint.SPEED : null; } } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabController.java index 4362848723..c213574ed3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TabController.java @@ -111,8 +111,10 @@ public final class TabController implements PageAware { if (previousContent instanceof PageAware pageAware) pageAware.onPageHidden(); if (contentPane != null) { - if (playAnimation && contentPane.getCurrentNode() != null) { - contentPane.setContent(content, ContainerAnimations.SLIDE_UP_FADE_IN, + if (playAnimation && previous != null && previous != tab && contentPane.getCurrentNode() != null) { + boolean forward = tabs.indexOf(tab) > tabs.indexOf(previous); + ContainerAnimations animation = forward ? ContainerAnimations.TAB_UP : ContainerAnimations.TAB_DOWN; + contentPane.setContent(content, animation, Motion.MEDIUM4, Motion.EASE_IN_OUT_CUBIC_EMPHASIZED); } else { contentPane.setContent(content, ContainerAnimations.NONE); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java index 36a434251d..0ae89e052c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java @@ -517,7 +517,7 @@ public class TerracottaControllerPage extends StackPane { } // Prevent the shadow of components from being clipped StackPane.setMargin(components, new Insets(0, 0, 5, 0)); - transition.setContent(components, ContainerAnimations.SLIDE_UP_FADE_IN); + transition.setContent(components, ContainerAnimations.TAB_UP); }; listener.changed(UI_STATE, null, UI_STATE.get()); holder.add(listener); @@ -605,7 +605,7 @@ public class TerracottaControllerPage extends StackPane { pane.getChildren().add(item); } - this.transition.setContent(pane, ContainerAnimations.SLIDE_UP_FADE_IN); + this.transition.setContent(pane, ContainerAnimations.TAB_UP); } } }