Package com.github.tommyettinger.textra
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 box is determined by the text bounds of the items and the size of the Styles.ListStyle.selection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.badlogic.gdx.utils.Array<T> intintprotected Styles.ListStylebooleanWhen this is true, typing a character while this list box is focused will jump focus to the first item in the list that starts with that character, ignoring case.Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
POOLS -
Constructor Summary
ConstructorsConstructorDescriptionTextraListBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin) TextraListBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin, String styleName) TextraListBox(Styles.ListStyle style) -
Method Summary
Modifier and TypeMethodDescriptionvoidact(float delta) voidvoiddraw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) protected voiddrawBackground(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) Called to draw the background.protected voiddrawSelection(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.scenes.scene2d.utils.Drawable drawable, float x, float y, float width, float height) intcom.badlogic.gdx.math.RectanglefloatgetCumulativeHeight(int index) Gets the total height of the item with the given index and all items before it.getItemAt(float y) intgetItemIndexAt(float y) com.badlogic.gdx.utils.Array<T> getItems()Returns the internal items array.com.badlogic.gdx.scenes.scene2d.InputListenerfloatfloatReturns the first selected item, or null.intcom.badlogic.gdx.scenes.scene2d.utils.ArraySelection<T> getStyle()Returns the list's style.booleanvoidlayout()voidsetAlignment(int alignment) Sets the horizontal alignment of the list items.voidsetCullingArea(com.badlogic.gdx.math.Rectangle cullingArea) voidSets the items visible in the list, clearing the selection if it is no longer valid.final voidvoidsetSelected(T item) Sets the selection to only the passed item, if it is a possible choice.voidsetSelectedIndex(int index) Sets the selection to only the selected index.voidsetSelection(com.badlogic.gdx.scenes.scene2d.utils.ArraySelection<T> selection) voidsetStyle(Styles.ListStyle style) voidsetTypeToSelect(boolean typeToSelect) Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validateMethods 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
-
Field Details
-
style
-
items
-
pressedIndex
public int pressedIndex -
overIndex
public int overIndex -
typeToSelect
public boolean typeToSelectWhen this is true, typing a character while this list box is focused will jump focus to the first item in the list that starts with that character, ignoring case.
When this is true, this does allocate some Strings every time the user types into a focused list box.
-
-
Constructor Details
-
TextraListBox
public TextraListBox(com.badlogic.gdx.scenes.scene2d.ui.Skin skin) -
TextraListBox
-
TextraListBox
-
-
Method Details
-
setStyle
-
getStyle
Returns the list's style. Modifying the returned style may not have an effect untilsetStyle(ListStyle)is called. -
layout
public void layout()- Specified by:
layoutin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
layoutin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
act
public void act(float delta) - Overrides:
actin classcom.badlogic.gdx.scenes.scene2d.Actor
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) - Overrides:
drawin classcom.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
-
setSelection
-
getSelected
Returns the first selected item, or null. -
setSelected
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
- Returns:
- May be null.
-
getPressedItem
- Returns:
- May be null.
-
getItemAt
- 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 at0and increases as the index increases.- Parameters:
index- the index of an item in this list box- Returns:
-Float.MAX_VALUEif index is negative or greater than or equal toitems.size
-
setItems
-
setItems
Sets the items visible in the list, clearing the selection if it is no longer valid. If a selection isSelection.getRequired(), the first item is selected. This can safely be called with a (modified) array returned fromgetItems(). -
clearItems
public void clearItems() -
getItems
Returns the internal items array. If modified,setItems(Array)must be called to reflect the changes. -
getPrefWidth
public float getPrefWidth()- Specified by:
getPrefWidthin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefWidthin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeightin interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout- Overrides:
getPrefHeightin classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
setCullingArea
public void setCullingArea(@Null com.badlogic.gdx.math.Rectangle cullingArea) - Specified by:
setCullingAreain interfacecom.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- SeeAlign.
-
getAlignment
public int getAlignment() -
getTypeToSelect
public boolean getTypeToSelect() -
setTypeToSelect
public void setTypeToSelect(boolean typeToSelect) -
getKeyListener
public com.badlogic.gdx.scenes.scene2d.InputListener getKeyListener()
-