summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2019-12-27 22:43:02 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2019-12-27 22:43:02 +0100
commit49b7c2aa90c3af33f455e7aa6c7935818e0df37a (patch)
tree1e61ccdea7921c613b4a2f35a3089fc93c8dcfbd /core/src
parente519042ba4720fd49b47c3c20eefcad5b42e2c1b (diff)
downloadgdx-boardgame-49b7c2aa90c3af33f455e7aa6c7935818e0df37a.zip
gdx-boardgame-49b7c2aa90c3af33f455e7aa6c7935818e0df37a.tar.gz
ui.List : selected use computePosition() instead of touch()
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/List.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/List.java b/core/src/ch/asynk/gdx/boardgame/ui/List.java
index 0c40a7b..3ed5985 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/List.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/List.java
@@ -30,6 +30,7 @@ public class List extends Element
this.layout = new GlyphLayout();
this.idx = null;
this.selected = new Bg(selected);
+ this.selected.setParent(this);
this.selected.visible = false;
this.sizing = Sizing.EXPAND_BOTH;
}
@@ -42,10 +43,13 @@ public class List extends Element
{
final Element touched = super.touch(x, y);
if (touched != null) {
- idx = (int) Math.floor((getInnerTop() - y) / itemHeight);
- if ((idx >= 0) && (idx < items.size())) {
- selected.setPosition(getX(), getInnerTop() - ((idx + 1) * itemHeight) + spacing / 2f, getWidth(), itemHeight);
- selected.visible = true;
+ int i = (int) Math.floor((getInnerTop() - y) / itemHeight);
+ if (i >= 0 && i < items.size()) {
+ if (idx == null || idx != i) {
+ idx = i;
+ selected.setPosition(0, getInnerHeight() - ((idx + 1) * itemHeight) + spacing / 2f, getWidth(), itemHeight);
+ selected.visible = true;
+ }
return touched;
}
}
@@ -81,6 +85,12 @@ public class List extends Element
}
}
+ @Override public void computePosition()
+ {
+ super.computePosition();
+ selected.computePosition();
+ }
+
@Override public void draw(Batch batch)
{
if (!visible) return;