Skip to content

Commit

Permalink
scene2d.ui, keep SelectBox popup from extending past right edge of st…
Browse files Browse the repository at this point in the history
…age.

Can happen with setSelectedPrefWidth(true).
  • Loading branch information
NathanSweet committed Mar 2, 2024
1 parent 7bed7d3 commit 9707171
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SelectBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9707171

Please sign in to comment.