From 97071719d19be261095122ec1d77af8e8bcdea84 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sat, 2 Mar 2024 12:35:18 -0400 Subject: [PATCH] scene2d.ui, keep SelectBox popup from extending past right edge of stage. Can happen with setSelectedPrefWidth(true). --- CHANGES | 1 + .../com/badlogic/gdx/scenes/scene2d/ui/SelectBox.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index d680c9e8934..2b23dbbd316 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,7 @@ - New GDX Setup projects now use Gradle 8.4 and AGP Plugin 8.1.2 which require at least Java 17. - Fixed Timer#stop, remember time spent stopped and delay tasks when started again. #7281 - Android: Add configuration option to render under the cutout if available on the device. +- Fix: Keep SelectBox popup from extending past right edge of stage. [1.12.1] - LWJGL3 Improvement: Audio device is automatically switched if it was changed in the operating system. diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.java index 5cf3354d945..0b780316c4f 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.java @@ -532,12 +532,19 @@ public void show (Stage stage) { setY(stagePosition.y - height); else setY(stagePosition.y + selectBox.getHeight()); - setX(stagePosition.x); + setHeight(height); validate(); float width = Math.max(getPrefWidth(), selectBox.getWidth()); setWidth(width); + float x = stagePosition.x; + if (x + width > stage.getWidth()) { + x -= getWidth() - selectBox.getWidth() - 1; + if (x < 0) x = 0; + } + setX(x); + validate(); scrollTo(0, list.getHeight() - selectBox.getSelectedIndex() * itemHeight - itemHeight / 2, 0, 0, true, true); updateVisualScroll();