private float prefWidth, prefHeight;\r
private float itemHeight;\r
private float textOffsetX, textOffsetY;\r
+ private boolean selectable;\r
\r
public List (Object[] items, Skin skin) {\r
this(items, skin.get(ListStyle.class));\r
setItems(items);\r
setWidth(getPrefWidth());\r
setHeight(getPrefHeight());\r
+ setSelectable(true);\r
\r
addListener(new InputListener() {\r
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {\r
if (pointer == 0 && button != 0) return false;\r
+ if (!List.this.isSelectable()) return false; // don't eat touch event when NOT selectable\r
List.this.touchDown(y);\r
return true;\r
}\r
});\r
}\r
+ \r
+ /**\r
+ * Sets whether or not this List's items are selectable.\r
+ *\r
+ * *NOTE*\r
+ * If the List is NOT selectable, it will NOT eat its touch events meaning they will still propagate down.\r
+ * Please be aware of this behavior change.\r
+ */\r
+ public void setSelectable(boolean s) {\r
+ selectable = s;\r
+ }\r
+ \r
+ /** @return Whether or not the List's items are selectable. */\r
+ public boolean isSelectable() {\r
+ return selectable;\r
+ }\r
\r
void touchDown (float y) {\r
int oldIndex = selectedIndex;\r
}\r
}\r
\r
- /** @return The index of the currently selected item. The top item has an index of 0. */\r
+ /** @return The index of the currently selected item. The top item has an index of 0. Nothing selected has an index of -1. */\r
public int getSelectedIndex () {\r
return selectedIndex;\r
}\r
selectedIndex = index;\r
}\r
\r
- /** @return The text of the currently selected item or null if the list is empty. */\r
+ /** @return The text of the currently selected item, else null if the list is empty or nothing is selected. */\r
public String getSelection () {\r
- if (items.length == 0) return null;\r
+ if (items.length == 0 || isNothingSelected()) return null;\r
return items[selectedIndex];\r
}\r
\r
- /** @return The index of the item that was selected, or -1. */\r
+ /**\r
+ * Sets the selection to the item if found, else sets the selection to nothing.\r
+ * @return The new index of the list selection\r
+ */\r
public int setSelection (String item) {\r
- selectedIndex = -1;\r
+ setSelectionToNothing();\r
+ \r
for (int i = 0, n = items.length; i < n; i++) {\r
if (items[i].equals(item)) {\r
selectedIndex = i;\r
return selectedIndex;\r
}\r
\r
+ /** Sets the list item selection to nothing with selection index value -1. */\r
+ public void setSelectionToNothing() {\r
+ selectedIndex = -1;\r
+ }\r
+ \r
+ /** @return Whether or not the list has an item selected. */\r
+ public boolean isNothingSelected() {\r
+ return selectedIndex == -1;\r
+ }\r
+ \r
+\r
public void setItems (Object[] objects) {\r
if (objects == null) throw new IllegalArgumentException("items cannot be null.");\r
\r