From f3181eaa423fa9fc2b30e7d66726ccdf9e84d3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 22 Feb 2016 00:25:04 +0100 Subject: List: correctly select, add Integer getIdx() --- core/src/ch/asynk/rustanddust/ui/List.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/ui/List.java b/core/src/ch/asynk/rustanddust/ui/List.java index ef4a5f9..0d5165a 100644 --- a/core/src/ch/asynk/rustanddust/ui/List.java +++ b/core/src/ch/asynk/rustanddust/ui/List.java @@ -36,14 +36,19 @@ public class List extends Widget this.selected = new Bg(game.getUiRegion(game.UI_SELECT)); } + public Integer getIdx() { return idx; } + @Override public boolean hit(float x, float y) { float t = (getTop() - (int) padding); idx = (int) Math.floor((t - y) / itemHeight); - if ((idx >= 0) && (idx < items.size())) + if ((idx >= 0) && (idx < items.size())) { selected.setPosition(rect.x, (t - itemHeight - (idx * itemHeight)), rect.width, (itemHeight + padding)); - return true; + return true; + } + idx = null; + return false; } public void setItems(int clipN, Collection items) -- cgit v1.1-2-g2b99