improved menu accessibility
parent
2375a5ed83
commit
3cb756a324
@ -1,45 +0,0 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.actors;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class AutoFocusScrollPane extends ScrollPane {
|
||||
|
||||
public AutoFocusScrollPane(Actor widget) {
|
||||
super(widget);
|
||||
init();
|
||||
}
|
||||
|
||||
public AutoFocusScrollPane(Actor widget, Skin skin) {
|
||||
super(widget, skin);
|
||||
init();
|
||||
}
|
||||
|
||||
public AutoFocusScrollPane(Actor widget, Skin skin, String styleName) {
|
||||
super(widget, skin, styleName);
|
||||
init();
|
||||
}
|
||||
|
||||
public AutoFocusScrollPane(Actor widget, ScrollPaneStyle style) {
|
||||
super(widget, style);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
addListener(new InputListener() {
|
||||
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
|
||||
var stage = getStage();
|
||||
if (stage != null) stage.setScrollFocus(AutoFocusScrollPane.this);
|
||||
}
|
||||
|
||||
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
|
||||
var stage = getStage();
|
||||
if (stage != null) stage.setScrollFocus(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.actors.game;
|
||||
package eu.jonahbauer.wizard.client.libgdx.actors;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.*;
|
||||
import eu.jonahbauer.wizard.client.libgdx.AnimationTimings;
|
@ -1,4 +1,4 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.actors.game;
|
||||
package eu.jonahbauer.wizard.client.libgdx.actors;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
@ -0,0 +1,36 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.listeners;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
|
||||
public class AutoFocusListener extends InputListener {
|
||||
@Override
|
||||
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
|
||||
var target = event.getTarget();
|
||||
|
||||
while (target != null && !(target instanceof ScrollPane)) {
|
||||
target = target.getParent();
|
||||
}
|
||||
|
||||
if (target instanceof ScrollPane pane) {
|
||||
event.getStage().setScrollFocus(pane);
|
||||
} else {
|
||||
event.getStage().setScrollFocus(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
|
||||
var target = event.getTarget();
|
||||
|
||||
while (target != null && !(target instanceof ScrollPane)) {
|
||||
target = target.getParent();
|
||||
}
|
||||
|
||||
if (target == null || toActor == null || !toActor.isDescendantOf(target)) {
|
||||
event.getStage().setScrollFocus(null);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.listeners;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button;
|
||||
|
||||
public class ButtonKeyListener extends InputListener {
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(InputEvent event, char character) {
|
||||
if ((character == '\n' || character == ' ') && event.getTarget() instanceof Button button) {
|
||||
button.toggle();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.listeners;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.UIUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KeyboardFocusManager extends InputListener {
|
||||
private final Stage stage;
|
||||
private final List<Actor> focusOrder;
|
||||
|
||||
public KeyboardFocusManager(Stage stage, List<Actor> focusOrder) {
|
||||
this.stage = stage;
|
||||
this.focusOrder = focusOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(InputEvent event, char character) {
|
||||
if (character == '\t') {
|
||||
var currentFocus = stage.getKeyboardFocus();
|
||||
var index = currentFocus == null ? -1 : focusOrder.indexOf(currentFocus);
|
||||
var count = focusOrder.size();
|
||||
if (count == 0) return true;
|
||||
|
||||
Actor nextFocus;
|
||||
if (index == -1) {
|
||||
nextFocus = focusOrder.get(UIUtils.shift() ? count - 1 : 0);
|
||||
} else {
|
||||
var direction = UIUtils.shift() ? -1 : 1;
|
||||
nextFocus = focusOrder.get(((index + direction) % count + count) % count);
|
||||
}
|
||||
|
||||
if (nextFocus instanceof TextField textField) {
|
||||
textField.selectAll();
|
||||
}
|
||||
|
||||
stage.setKeyboardFocus(nextFocus);
|
||||
event.stop();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package eu.jonahbauer.wizard.client.libgdx.listeners;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
|
||||
|
||||
public class SelectBoxListener extends InputListener {
|
||||
private final SelectBox<?> selectBox;
|
||||
|
||||
public SelectBoxListener(SelectBox<?> selectBox) {
|
||||
this.selectBox = selectBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyDown(InputEvent event, int keycode) {
|
||||
var size = selectBox.getItems().size;
|
||||
if (size == 0) return false;
|
||||
|
||||
switch (keycode) {
|
||||
case Input.Keys.UP -> {
|
||||
var index = selectBox.getSelectedIndex();
|
||||
if (index == -1) {
|
||||
selectBox.setSelectedIndex(size - 1);
|
||||
} else {
|
||||
selectBox.setSelectedIndex(MathUtils.clamp(index - 1, 0, size - 1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case Input.Keys.DOWN -> {
|
||||
var index = selectBox.getSelectedIndex();
|
||||
if (index == -1) {
|
||||
selectBox.setSelectedIndex(0);
|
||||
} else {
|
||||
selectBox.setSelectedIndex(MathUtils.clamp(index + 1, 0, size - 1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 202 B |
Binary file not shown.
After Width: | Height: | Size: 157 B |
Loading…
Reference in New Issue