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 TextraLabel
s 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
FieldsModifier and TypeFieldDescriptionprotected final com.badlogic.gdx.utils.Array<T>
int
int
protected Styles.ListStyle
boolean
-
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 TypeMethodDescriptionvoid
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
getCumulativeHeight
(int index) 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>
getItems()
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>
getStyle()
Returns the list's style.void
layout()
void
setAlignment
(int alignment) Sets the horizontal alignment of the list items.void
setCullingArea
(com.badlogic.gdx.math.Rectangle cullingArea) void
Sets the items visible in the list, clearing the selection if it is no longer valid.final void
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
setStyle
(Styles.ListStyle style) 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
-
Field Details
-
style
-
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
-
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:
layout
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
layout
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
act
public void act(float delta) - Overrides:
act
in classcom.badlogic.gdx.scenes.scene2d.Actor
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha) - Overrides:
draw
in 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 at0
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 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:
getPrefWidth
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
getPrefWidth
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
getPrefHeight
public float getPrefHeight()- Specified by:
getPrefHeight
in interfacecom.badlogic.gdx.scenes.scene2d.utils.Layout
- Overrides:
getPrefHeight
in classcom.badlogic.gdx.scenes.scene2d.ui.Widget
-
setCullingArea
public void setCullingArea(@Null com.badlogic.gdx.math.Rectangle cullingArea) - Specified by:
setCullingArea
in 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() -
setTypeToSelect
public void setTypeToSelect(boolean typeToSelect) -
getKeyListener
public com.badlogic.gdx.scenes.scene2d.InputListener getKeyListener()
-