根据 Tab 相对位置选择动画方向 (#7172)
This commit is contained in:
1 parent
8912ee2661
commit
d3b91d439c
4 files changed
+58
-23
No files matched your search
@@ -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)));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user