Skip to content

Commit

Permalink
Fixed dialog focus issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed May 25, 2024
1 parent 5a944ef commit f0d4fdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions arc-core/src/arc/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ public void unfocus(Element actor){
*/
public boolean setKeyboardFocus(Element actor){
if(keyboardFocus == actor) return true;

FocusEvent event = Pools.obtain(FocusEvent.class, FocusEvent::new);
event.type = (FocusEvent.Type.keyboard);
Element oldKeyboardFocus = keyboardFocus;
Expand Down
15 changes: 14 additions & 1 deletion arc-core/src/arc/scene/ui/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import arc.scene.style.*;
import arc.scene.ui.Label.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import arc.util.pooling.*;

Expand Down Expand Up @@ -286,7 +287,19 @@ public void act(float delta){
@Override
public void draw(){
Scene stage = getScene();
if(stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this);

if(stage.getKeyboardFocus() == null){
//get top dialog in the scene and focus keyboard on that
int highestDialog = -1;
Seq<Element> children = scene.root.getChildren();
for(int i = children.size - 1; i >= 0; i--){
if(children.get(i) instanceof Dialog){
highestDialog = i;
break;
}
}
stage.setKeyboardFocus(highestDialog == -1 ? this : children.get(highestDialog));
}

if(style.stageBackground != null){
stageToLocalCoordinates(tmpPosition.set(translation.x, translation.y));
Expand Down

0 comments on commit f0d4fdb

Please sign in to comment.