Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable SelectBoxScrollPane reset selection on exit behavior #7234

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 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 @@ -426,6 +426,7 @@ static public class SelectBoxScrollPane<T> extends ScrollPane {
final List<T> list;
private InputListener hideListener;
private Actor previousScrollFocus;
boolean resetSelectionOnExit = false;

public SelectBoxScrollPane (final SelectBox<T> selectBox) {
super(null, selectBox.style.scrollStyle);
Expand Down Expand Up @@ -458,7 +459,7 @@ public boolean mouseMoved (InputEvent event, float x, float y) {

addListener(new InputListener() {
public void exit (InputEvent event, float x, float y, int pointer, @Null Actor toActor) {
if (toActor == null || !isAscendantOf(toActor)) {
if ((toActor == null || !isAscendantOf(toActor)) && resetSelectionOnExit) {
T selected = selectBox.getSelected();
if (selected != null) list.selection.set(selected);
}
Expand Down Expand Up @@ -490,6 +491,10 @@ public boolean keyDown (InputEvent event, int keycode) {
};
}

public void setResetSelectionOnExit (boolean resetSelectionOnExit) {
this.resetSelectionOnExit = resetSelectionOnExit;
}

/** Allows a subclass to customize the select box list. The default implementation returns a list that delegates
* {@link List#toString(Object)} to {@link SelectBox#toString(Object)}. */
protected List<T> newList () {
Expand Down