From e9e6ef1f20cb74da457ec80eb161823e1ce38e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=9E=E5=BA=90?= <109708109+CiiLu@users.noreply.github.com> Date: Tue, 27 Jan 2026 20:42:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20JFXPopup=20?= =?UTF-8?q?=E5=9C=A8=20RTL=20=E4=B8=8B=E6=BC=82=E7=A7=BB=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#5328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jfoenix/controls/JFXPopup.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/HMCL/src/main/java/com/jfoenix/controls/JFXPopup.java b/HMCL/src/main/java/com/jfoenix/controls/JFXPopup.java index 41accd48a..b3e40b6f2 100644 --- a/HMCL/src/main/java/com/jfoenix/controls/JFXPopup.java +++ b/HMCL/src/main/java/com/jfoenix/controls/JFXPopup.java @@ -24,8 +24,10 @@ import javafx.application.Platform; import javafx.beans.DefaultProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; +import javafx.geometry.NodeOrientation; import javafx.geometry.Point2D; import javafx.scene.Node; +import javafx.scene.Scene; import javafx.scene.control.PopupControl; import javafx.scene.control.Skin; import javafx.scene.layout.Pane; @@ -41,7 +43,12 @@ import javafx.stage.Window; public class JFXPopup extends PopupControl { public enum PopupHPosition { - RIGHT, LEFT + RIGHT, + LEFT; + + public PopupHPosition getOpposite() { + return (this == RIGHT) ? LEFT : RIGHT; + } } public enum PopupVPosition { @@ -121,18 +128,21 @@ public class JFXPopup extends PopupControl { /// @param initOffsetY on the y-axis public void show(Node node, PopupVPosition vAlign, PopupHPosition hAlign, double initOffsetX, double initOffsetY) { if (!isShowing()) { - if (node.getScene() == null || node.getScene().getWindow() == null) { + Scene scene = node.getScene(); + if (scene == null || scene.getWindow() == null) { throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); } - Window parent = node.getScene().getWindow(); + Window parent = scene.getWindow(); final Point2D origin = node.localToScene(0, 0); - final double anchorX = parent.getX() + origin.getX() - + node.getScene().getX() + (hAlign == PopupHPosition.RIGHT ? ((Region) node).getWidth() : 0); - final double anchorY = parent.getY() + origin.getY() - + node.getScene() - .getY() + (vAlign == PopupVPosition.BOTTOM ? ((Region) node).getHeight() : 0); - this.show(parent, anchorX, anchorY); - ((JFXPopupSkin) getSkin()).reset(vAlign, hAlign, initOffsetX, initOffsetY); + + boolean isRTL = node.getEffectiveNodeOrientation() == NodeOrientation.RIGHT_TO_LEFT; + + this.show(parent, + parent.getX() + scene.getX() + origin.getX() + (hAlign == PopupHPosition.RIGHT ? ((Region) node).getWidth() : 0), + parent.getY() + origin.getY() + scene.getY() + (vAlign == PopupVPosition.BOTTOM ? ((Region) node).getHeight() : 0) + ); + + ((JFXPopupSkin) getSkin()).reset(vAlign, isRTL ? hAlign.getOpposite() : hAlign, isRTL ? -initOffsetX : initOffsetX, initOffsetY); Platform.runLater(() -> ((JFXPopupSkin) getSkin()).animate()); } }