diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java index 4993bb7019..ea884783d1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -23,6 +23,7 @@ import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; +import javafx.animation.PauseTransition; import javafx.beans.InvalidationListener; import javafx.beans.WeakInvalidationListener; import javafx.beans.property.DoubleProperty; @@ -239,28 +240,41 @@ public static void initialize(Stage stage) { Controllers.stage = stage; + final Duration DEBOUNCE_DELAY = Duration.millis(600); + final PauseTransition debounceX = new PauseTransition(DEBOUNCE_DELAY); + final PauseTransition debounceY = new PauseTransition(DEBOUNCE_DELAY); + final PauseTransition debounceWidth = new PauseTransition(DEBOUNCE_DELAY); + final PauseTransition debounceHeight = new PauseTransition(DEBOUNCE_DELAY); + stageSizeChangeListener = o -> { ReadOnlyDoubleProperty sourceProperty = (ReadOnlyDoubleProperty) o; DoubleProperty targetProperty; + PauseTransition debounce; + switch (sourceProperty.getName()) { case "x": { targetProperty = stageX; + debounce = debounceX; break; } case "y": { targetProperty = stageY; + debounce = debounceY; break; } case "width": { targetProperty = stageWidth; + debounce = debounceWidth; break; } case "height": { targetProperty = stageHeight; + debounce = debounceHeight; break; } default: { targetProperty = null; + debounce = null; } } @@ -272,6 +286,33 @@ public static void initialize(Stage stage) { !Controllers.stage.isFullScreen() && !Controllers.stage.isMaximized()) ) { targetProperty.set(sourceProperty.get()); + + final String name = sourceProperty.getName(); + final double value = sourceProperty.get(); + + if (debounce != null) { + debounce.setOnFinished(event -> { + switch (name) { + case "x": { + config().setX(value / SCREEN.getBounds().getWidth()); + break; + } + case "y": { + config().setY(value / SCREEN.getBounds().getHeight()); + break; + } + case "width": { + config().setWidth(value); + break; + } + case "height": { + config().setHeight(value); + break; + } + } + }); + debounce.playFromStart(); + } } };