Class TextraSelectBox

java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.ui.Widget
com.github.tommyettinger.textra.TextraSelectBox
All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Disableable, com.badlogic.gdx.scenes.scene2d.utils.Layout
Direct Known Subclasses:
TypingSelectBox

public class TextraSelectBox extends com.badlogic.gdx.scenes.scene2d.ui.Widget implements com.badlogic.gdx.scenes.scene2d.utils.Disableable
A select box (aka a drop-down list) allows a user to choose one of a number of values from a list. When inactive, the selected value is displayed. When activated, it shows the list of values that may be selected.

ChangeListener.ChangeEvent is fired when the select box selection changes.

The preferred size of the select box is determined by the maximum text bounds of the items and the size of the Styles.SelectBoxStyle.background.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The scroll pane shown when a select box is open.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextraSelectBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin)
     
    TextraSelectBox(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
    drawItem(com.badlogic.gdx.graphics.g2d.Batch batch, TextraLabel item, float x, float y, float width)
     
    protected com.badlogic.gdx.scenes.scene2d.utils.Drawable
    Returns appropriate background drawable from the style based on the current select box state.
    com.badlogic.gdx.scenes.scene2d.utils.ClickListener
     
    protected com.badlogic.gdx.graphics.Color
    Returns the appropriate label font color from the style based on the current button state.
    com.badlogic.gdx.utils.Array<TextraLabel>
    Returns the internal items array.
    Returns the list shown when the select box is open.
    int
     
    float
    Returns the pref width of the select box if the widest item was selected, for use when setSelectedPrefWidth(boolean) is true.
    float
     
    float
     
    Returns the scroll pane containing the list that is shown when the select box is open.
    Returns the first selected item, or null.
    int
     
    boolean
     
    com.badlogic.gdx.scenes.scene2d.utils.ArraySelection<TextraLabel>
    Get the set of selected items, useful when multiple items are selected
    Returns the select box's style.
    void
    Deprecated.
    void
     
    boolean
     
    boolean
     
    void
     
    protected TextraLabel
    newLabel(String markupText, Font font, com.badlogic.gdx.graphics.Color color)
     
    Allows a subclass to customize the scroll pane shown when the select box is open.
    protected void
    onHide(com.badlogic.gdx.scenes.scene2d.Actor scrollPane)
     
    protected void
    onShow(com.badlogic.gdx.scenes.scene2d.Actor scrollPane, boolean below)
     
    void
    setAlignment(int alignment)
    Sets the alignment of the selected item in the select box.
    void
    setDisabled(boolean disabled)
     
    void
    setItems(com.badlogic.gdx.utils.Array<? extends TextraLabel> newItems)
    Sets the items visible in the select box.
    void
    setItems(TextraLabel... newItems)
    Set the backing Array that makes up the choices available in the SelectBox.
    void
    setItemTexts(String... newMarkupTexts)
    Sets the choices available in the SelectBox using an array or varargs of markup Strings.
    void
    setMaxListCount(int maxListCount)
    Set the max number of items to display when the select box is opened.
    void
    Disables scrolling of the list shown when the select box is open.
    void
    Sets the selection to only the passed item, if it is a possible choice, else selects the first item.
    void
    setSelectedIndex(int index)
    Sets the selection to only the selected index.
    void
    setSelectedPrefWidth(boolean selectedPrefWidth)
    When true the pref width is based on the selected item.
    protected void
    setStage(com.badlogic.gdx.scenes.scene2d.Stage stage)
     
    void
     
    void
    Deprecated.
    void
     
    protected String
     

    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, 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
  • Constructor Details

    • TextraSelectBox

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

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

      public TextraSelectBox(Styles.SelectBoxStyle style)
  • Method Details

    • newScrollPane

      protected TextraSelectBox.SelectBoxScrollPane newScrollPane()
      Allows a subclass to customize the scroll pane shown when the select box is open.
    • setMaxListCount

      public void setMaxListCount(int maxListCount)
      Set the max number of items to display when the select box is opened. Set to 0 (the default) to display as many as fit in the stage height.
    • getMaxListCount

      public int getMaxListCount()
      Returns:
      Max number of items to display when the box is opened, or <= 0 to display them all.
    • setStage

      protected void setStage(com.badlogic.gdx.scenes.scene2d.Stage stage)
      Overrides:
      setStage in class com.badlogic.gdx.scenes.scene2d.Actor
    • setStyle

      public void setStyle(Styles.SelectBoxStyle style)
    • getStyle

      public Styles.SelectBoxStyle getStyle()
      Returns the select box's style. Modifying the returned style may not have an effect until setStyle(Styles.SelectBoxStyle) is called.
    • setItemTexts

      public void setItemTexts(String... newMarkupTexts)
      Sets the choices available in the SelectBox using an array or varargs of markup Strings. Marks up each String in newMarkupTexts as a TextraLabel and adds that label to the choices.
      Parameters:
      newMarkupTexts - an array or varargs of individual markup Strings, one per choice
    • setItems

      public void setItems(TextraLabel... newItems)
      Set the backing Array that makes up the choices available in the SelectBox.
    • setItems

      public void setItems(com.badlogic.gdx.utils.Array<? extends TextraLabel> newItems)
      Sets the items visible in the select box.
    • clearItems

      public void clearItems()
    • getItems

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

      @Null protected com.badlogic.gdx.scenes.scene2d.utils.Drawable getBackgroundDrawable()
      Returns appropriate background drawable from the style based on the current select box state.
    • getFontColor

      protected com.badlogic.gdx.graphics.Color getFontColor()
      Returns the appropriate label font color from the style based on the current button state.
    • draw

      public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
      Overrides:
      draw 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
    • drawItem

      protected void drawItem(com.badlogic.gdx.graphics.g2d.Batch batch, TextraLabel item, float x, float y, float width)
    • setAlignment

      public void setAlignment(int alignment)
      Sets the alignment of the selected item in the select box. See getList() and List.setAlignment(int) to set the alignment in the list shown when the select box is open.
      Parameters:
      alignment - See Align.
    • getSelection

      public com.badlogic.gdx.scenes.scene2d.utils.ArraySelection<TextraLabel> getSelection()
      Get the set of selected items, useful when multiple items are selected
      Returns:
      a Selection object containing the selected elements
    • getSelected

      @Null public TextraLabel getSelected()
      Returns the first selected item, or null. For multiple selections use SelectBox.getSelection().
    • setSelected

      public void setSelected(@Null TextraLabel item)
      Sets the selection to only the passed item, if it is a possible choice, else selects the first item.
    • 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.
    • setSelectedPrefWidth

      public void setSelectedPrefWidth(boolean selectedPrefWidth)
      When true the pref width is based on the selected item.
    • getSelectedPrefWidth

      public boolean getSelectedPrefWidth()
    • getMaxPrefWidth

      public float getMaxPrefWidth()
      Returns the pref width of the select box if the widest item was selected, for use when setSelectedPrefWidth(boolean) is true.
    • setDisabled

      public void setDisabled(boolean disabled)
      Specified by:
      setDisabled in interface com.badlogic.gdx.scenes.scene2d.utils.Disableable
    • isDisabled

      public boolean isDisabled()
      Specified by:
      isDisabled in interface com.badlogic.gdx.scenes.scene2d.utils.Disableable
    • 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
    • toString

      protected String toString(TextraLabel item)
    • showList

      @Deprecated public void showList()
      Deprecated.
    • showScrollPane

      public void showScrollPane()
    • hideList

      @Deprecated public void hideList()
      Deprecated.
    • hideScrollPane

      public void hideScrollPane()
    • getList

      public TextraListBox<TextraLabel> getList()
      Returns the list shown when the select box is open.
    • setScrollingDisabled

      public void setScrollingDisabled(boolean y)
      Disables scrolling of the list shown when the select box is open.
    • getScrollPane

      public TextraSelectBox.SelectBoxScrollPane getScrollPane()
      Returns the scroll pane containing the list that is shown when the select box is open.
    • isOver

      public boolean isOver()
    • getClickListener

      public com.badlogic.gdx.scenes.scene2d.utils.ClickListener getClickListener()
    • onShow

      protected void onShow(com.badlogic.gdx.scenes.scene2d.Actor scrollPane, boolean below)
    • onHide

      protected void onHide(com.badlogic.gdx.scenes.scene2d.Actor scrollPane)
    • newLabel

      protected TextraLabel newLabel(String markupText, Font font, com.badlogic.gdx.graphics.Color color)