Class TextraListBox<T extends TextraLabel>

java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.github.tommyettinger.textra.TextraListBox<T>
All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Cullable, com.badlogic.gdx.scenes.scene2d.utils.Layout
Direct Known Subclasses:
TypingListBox

public class TextraListBox<T extends TextraLabel> extends com.badlogic.gdx.scenes.scene2d.ui.Widget implements com.badlogic.gdx.scenes.scene2d.utils.Cullable
A TextraListBox (based on List) displays TextraLabels and highlights the currently selected item.

A 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 Styles.ListStyle.selection.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final com.badlogic.gdx.utils.Array<T>
     
    int
     
    int
     
     
    boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextraListBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
     
    TextraListBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    act(float delta)
     
    void
     
    void
    draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
     
    protected void
    drawBackground(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
    Called to draw the background.
    protected void
    drawSelection(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable, float x, float y, float width, float height)
     
    int
     
    com.badlogic.gdx.math.Rectangle
     
    float
    Gets the total height of the item with the given index and all items before it.
    getItemAt(float y)
     
    int
    getItemIndexAt(float y)
     
    com.badlogic.gdx.utils.Array<T>
    Returns the internal items array.
    com.badlogic.gdx.scenes.scene2d.InputListener
     
     
    float
     
    float
     
     
    Returns the first selected item, or null.
    int
     
    com.badlogic.gdx.scenes.scene2d.utils.ArraySelection<T>
     
    Returns the list's style.
    void
     
    void
    setAlignment(int alignment)
    Sets the horizontal alignment of the list items.
    void
    setCullingArea(com.badlogic.gdx.math.Rectangle cullingArea)
     
    void
    setItems(com.badlogic.gdx.utils.Array<? extends T> newItems)
    Sets the items visible in the list, clearing the selection if it is no longer valid.
    final void
    setItems(T... newItems)
     
    void
    setSelected(T item)
    Sets the selection to only the passed item, if it is a possible choice.
    void
    setSelectedIndex(int index)
    Sets the selection to only the selected index.
    void
    setSelection(com.badlogic.gdx.scenes.scene2d.utils.ArraySelection<T> selection)
     
    void
     
    void
    setTypeToSelect(boolean typeToSelect)
     

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget

    getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor

    addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, hit, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • style

      protected Styles.ListStyle style
    • items

      protected final com.badlogic.gdx.utils.Array<T extends TextraLabel> items
    • pressedIndex

      public int pressedIndex
    • overIndex

      public int overIndex
    • typeToSelect

      public boolean typeToSelect
  • Constructor Details

    • TextraListBox

      public TextraListBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
    • TextraListBox

      public TextraListBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName)
    • TextraListBox

      public TextraListBox(Styles.ListStyle style)
  • Method Details

    • setStyle

      public void setStyle(Styles.ListStyle style)
    • getStyle

      public Styles.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()
      Specified by:
      layout in interface com.badlogic.gdx.scenes.scene2d.utils.Layout
      Overrides:
      layout in class com.badlogic.gdx.scenes.scene2d.ui.Widget
    • act

      public void act(float delta)
      Overrides:
      act in class com.badlogic.gdx.scenes.scene2d.Actor
    • draw

      public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
      Overrides:
      draw in class com.badlogic.gdx.scenes.scene2d.ui.Widget
    • drawSelection

      protected void drawSelection(com.badlogic.gdx.graphics.g2d.Batch batch, @Null com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable, float x, float y, float width, float height)
    • drawBackground

      protected void drawBackground(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
      Called to draw the background. Default implementation draws the style background drawable.
    • getSelection

      public com.badlogic.gdx.scenes.scene2d.utils.ArraySelection<T> getSelection()
    • setSelection

      public void setSelection(com.badlogic.gdx.scenes.scene2d.utils.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.
    • getCumulativeHeight

      public float getCumulativeHeight(int index)
      Gets the total height of the item with the given index and all items before it. This starts at 0 and increases as the index increases.
      Parameters:
      index - the index of an item in this list box
      Returns:
      -Float.MAX_VALUE if index is negative or greater than or equal to items.size
    • setItems

      @SafeVarargs public final void setItems(T... newItems)
    • setItems

      public void setItems(com.badlogic.gdx.utils.Array<? extends T> 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 com.badlogic.gdx.utils.Array<T> getItems()
      Returns the internal items array. If modified, setItems(Array) must be called to reflect the changes.
    • getPrefWidth

      public float getPrefWidth()
      Specified by:
      getPrefWidth in interface com.badlogic.gdx.scenes.scene2d.utils.Layout
      Overrides:
      getPrefWidth in class com.badlogic.gdx.scenes.scene2d.ui.Widget
    • getPrefHeight

      public float getPrefHeight()
      Specified by:
      getPrefHeight in interface com.badlogic.gdx.scenes.scene2d.utils.Layout
      Overrides:
      getPrefHeight in class com.badlogic.gdx.scenes.scene2d.ui.Widget
    • setCullingArea

      public void setCullingArea(@Null com.badlogic.gdx.math.Rectangle cullingArea)
      Specified by:
      setCullingArea in interface com.badlogic.gdx.scenes.scene2d.utils.Cullable
    • getCullingArea

      public com.badlogic.gdx.math.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 com.badlogic.gdx.scenes.scene2d.InputListener getKeyListener()