Class List<T>

All Implemented Interfaces:
Cullable, Layout

public class List<T> extends Widget implements Cullable
A list (aka list box) displays textual items and highlights the currently selected item.

ChangeListener.ChangeEvent is fired when the list selection changes.

The preferred size of the list is determined by the text bounds of the items and the size of the List.ListStyle.selection.

Author:
mzechner, Nathan Sweet
  • Constructor Details

  • Method Details

    • setStyle

      public void setStyle(List.ListStyle style)
    • getStyle

      public List.ListStyle getStyle()
      Returns the list's style. Modifying the returned style may not have an effect until setStyle(ListStyle) is called.
    • layout

      public void layout()
      Description copied from interface: Layout
      Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Layout.invalidate() on any each child whose width or height has changed, and calls Layout.validate() on each child. This method should almost never be called directly, instead Layout.validate() should be used.
      Specified by:
      layout in interface Layout
      Overrides:
      layout in class Widget
    • draw

      public void draw(Batch batch, float parentAlpha)
      Description copied from class: Widget
      If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.
      Overrides:
      draw in class Widget
      parentAlpha - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
    • getSelection

      public ArraySelection<T> getSelection()
    • setSelection

      public void setSelection(ArraySelection<T> selection)
    • getSelected

      @Null public T getSelected()
      Returns the first selected item, or null.
    • setSelected

      public void setSelected(@Null T item)
      Sets the selection to only the passed item, if it is a possible choice.
      Parameters:
      item - May be null.
    • getSelectedIndex

      public int getSelectedIndex()
      Returns:
      The index of the first selected item. The top item has an index of 0. Nothing selected has an index of -1.
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Sets the selection to only the selected index.
      Parameters:
      index - -1 to clear the selection.
    • getOverItem

      public T getOverItem()
      Returns:
      May be null.
    • getPressedItem

      public T getPressedItem()
      Returns:
      May be null.
    • getItemAt

      @Null public T getItemAt(float y)
      Returns:
      null if not over an item.
    • getItemIndexAt

      public int getItemIndexAt(float y)
      Returns:
      -1 if not over an item.
    • setItems

      public void setItems(T... newItems)
    • setItems

      public void setItems(Array newItems)
      Sets the items visible in the list, clearing the selection if it is no longer valid. If a selection is Selection.getRequired(), the first item is selected. This can safely be called with a (modified) array returned from getItems().
    • clearItems

      public void clearItems()
    • getItems

      public Array<T> getItems()
      Returns the internal items array. If modified, setItems(Array) must be called to reflect the changes.
    • getItemHeight

      public float getItemHeight()
    • getPrefWidth

      public float getPrefWidth()
      Specified by:
      getPrefWidth in interface Layout
      Overrides:
      getPrefWidth in class Widget
    • getPrefHeight

      public float getPrefHeight()
      Specified by:
      getPrefHeight in interface Layout
      Overrides:
      getPrefHeight in class Widget
    • toString

      public String toString(T object)
    • setCullingArea

      public void setCullingArea(@Null Rectangle cullingArea)
      Specified by:
      setCullingArea in interface Cullable
      Parameters:
      cullingArea - The culling area in the child actor's coordinates.
    • getCullingArea

      public Rectangle getCullingArea()
      Returns:
      May be null.
      See Also:
    • setAlignment

      public void setAlignment(int alignment)
      Sets the horizontal alignment of the list items.
      Parameters:
      alignment - See Align.
    • getAlignment

      public int getAlignment()
    • setTypeToSelect

      public void setTypeToSelect(boolean typeToSelect)
    • getKeyListener

      public InputListener getKeyListener()