public class TextPanel
extends java.lang.Object
SquidPanel
) as in these examples (no scrolling first, then with a
scroll bar):
It supports vertical scrolling, i.e. it'll put a vertical scrollbar if there's too much text to display. This class does a lot of stuff, you typically only have to provide the textures for the scrollbars and the scroll knobs (see example below).
A typical usage of this class is as follows:
final TextPanel<Color> tp = new TextPanel<>(new GDXMarkup(), font);
tp.init(screenWidth, screenHeight, text); <- first 2 params: for fullscreen
final ScrollPane sp = tp.getScrollPane();
sp.setScrollPaneStyle(new ScrollPaneStyle(...)); <- set textures
stage.addActor(sp);
stage.setScrollFocus(sp);
stage.draw();
This class shares what ScrollPane
does (knobs, handling of the wheel).
Drawing the result of getScrollPane()
will set the shader of batch
if using a distance field or MSDF
font and the shader is currently not configured for such a font; it does not reset the shader to the default so that
multiple Actors can all use the same shader and so specific extra glyphs or other items can be rendered after calling
draw(). If you need to draw both a distance field font and full-color art, you should set the shader on the Batch to
null when you want to draw full-color art, and end the Batch between drawing this object and the other art.
A libGDX widget for general scrolling through only the visible part of a large widget
Modifier and Type | Field and Description |
---|---|
com.badlogic.gdx.graphics.Color |
backgroundColor
The color to use to paint the background (outside buttons) using
ShapeRenderer . |
com.badlogic.gdx.graphics.Color |
borderColor
The color of the border around this panel, if any.
|
float |
borderSize
The size of the border, if any
|
UIUtil.CornerStyle |
borderStyle |
protected com.badlogic.gdx.graphics.g2d.BitmapFont |
font |
protected com.badlogic.gdx.scenes.scene2d.ui.ScrollPane |
scrollPane |
protected TextCellFactory |
tcf |
java.util.ArrayList<java.lang.CharSequence> |
text
The text to display
|
protected com.badlogic.gdx.scenes.scene2d.Actor |
textActor
The actor whose size is adjusted to the text.
|
Constructor and Description |
---|
TextPanel(com.badlogic.gdx.graphics.g2d.BitmapFont font)
The text to display MUST be set later on with
init(float, float, Collection) . |
TextPanel(TextCellFactory font)
The text to display MUST be set later on with
init(float, float, Collection) (which can't be updated) or
initShared(float, float, ArrayList) (which reflects changes in the given ArrayList). |
Modifier and Type | Method and Description |
---|---|
protected com.badlogic.gdx.graphics.glutils.ShapeRenderer |
buildRenderer() |
void |
dispose() |
void |
drawBorder(com.badlogic.gdx.graphics.g2d.Batch batch)
Draws the border.
|
TextCellFactory |
getFont() |
protected com.badlogic.gdx.graphics.glutils.ShapeRenderer |
getRenderer() |
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane |
getScrollPane() |
com.badlogic.gdx.scenes.scene2d.Actor |
getTextActor() |
java.util.ArrayList<java.lang.String> |
getTypesetText() |
void |
init(float width,
float maxHeight,
java.util.Collection<? extends squidpony.panel.IColoredString<com.badlogic.gdx.graphics.Color>> coloredText)
This method sets the sizes of
scrollPane and textActor . |
void |
init(float width,
float maxHeight,
com.badlogic.gdx.graphics.Color color,
java.lang.String... text) |
void |
initShared(float width,
float maxHeight,
java.util.ArrayList<java.lang.CharSequence> text)
This method sets the sizes of
scrollPane and textActor , and shares a direct reference to
text so changes to that ArrayList will also be picked up here and rendered. |
protected void |
prepareText()
Updates the text this will show based on the current contents of the ArrayList of IColoredString values that may
be shared due to
initShared(float, float, ArrayList) , then resizes the getTextActor() to fit
the current text and lays out the getScrollPane() to match. |
void |
scroll(float downDistance)
Scrolls the scroll pane this holds down by some number of rows (which may be fractional, and may be negative to
scroll up).
|
void |
scrollToEdge(boolean goToTop)
If the parameter is true, scrolls to the top of this scroll pane; otherwise scrolls to the bottom.
|
void |
setFont(com.badlogic.gdx.graphics.g2d.BitmapFont font)
Sets the font to use.
|
void |
setFont(TextCellFactory font)
Sets the font to use.
|
protected void |
yScrollingCallback(boolean required)
Callback done to do stuff according to whether y-scrolling is required
|
public com.badlogic.gdx.graphics.Color backgroundColor
ShapeRenderer
. Or null
to disable background coloring.public com.badlogic.gdx.graphics.Color borderColor
ShapeRenderer
and borderStyle
.public float borderSize
public UIUtil.CornerStyle borderStyle
protected com.badlogic.gdx.graphics.g2d.BitmapFont font
protected TextCellFactory tcf
public java.util.ArrayList<java.lang.CharSequence> text
protected final com.badlogic.gdx.scenes.scene2d.ui.ScrollPane scrollPane
protected final com.badlogic.gdx.scenes.scene2d.Actor textActor
scrollPane
.public TextPanel(com.badlogic.gdx.graphics.g2d.BitmapFont font)
init(float, float, Collection)
.font
- The font to use. It can be set later using
setFont(BitmapFont)
, but it MUST be set before
drawing this panel.public TextPanel(TextCellFactory font)
init(float, float, Collection)
(which can't be updated) or
initShared(float, float, ArrayList)
(which reflects changes in the given ArrayList).font
- A TextCellFactory, typically holding a distance field font ("stretchable" or "crisp" in
DefaultResources). This won't force glyphs into same-size cells, despite the name.public void setFont(com.badlogic.gdx.graphics.g2d.BitmapFont font)
init(float, float, Collection)
if the
font wasn't given at creation-time.font
- The font to use as a BitmapFont.public void setFont(TextCellFactory font)
init(float, float, Collection)
if the
font wasn't given at creation-time.font
- The font to use as a TextCellFactory.public void init(float width, float maxHeight, java.util.Collection<? extends squidpony.panel.IColoredString<com.badlogic.gdx.graphics.Color>> coloredText)
scrollPane
and textActor
.
This method MUST be called before rendering.maxHeight
- The maximum height that the scrollpane can take (equal or
smaller than the height of the text actor).width
- The width of the scrollpane and the text actor.coloredText
- any Collection of IColoredString that use Color or a subclass as their color typepublic void initShared(float width, float maxHeight, java.util.ArrayList<java.lang.CharSequence> text)
scrollPane
and textActor
, and shares a direct reference to
text
so changes to that ArrayList will also be picked up here and rendered.
This method MUST be called before rendering.maxHeight
- The maximum height that the scrollpane can take (equal or
smaller than the height of the text actor).width
- The width of the scrollpane and the text actor.text
- an ArrayList of CharSequence that will be used directly by this TextPanel (changes
to the ArrayList will show up in the TextPanel)public void init(float width, float maxHeight, com.badlogic.gdx.graphics.Color color, java.lang.String... text)
public void drawBorder(com.badlogic.gdx.graphics.g2d.Batch batch)
batch
- public java.util.ArrayList<java.lang.String> getTypesetText()
text
.protected void prepareText()
initShared(float, float, ArrayList)
, then resizes the getTextActor()
to fit
the current text and lays out the getScrollPane()
to match. Called in the text actor's draw() method.public void scroll(float downDistance)
downDistance
- The distance in rows to scroll down, which can be negative to scroll up insteadpublic void scrollToEdge(boolean goToTop)
goToTop
- If true, will scroll to the top edge; if false, will scroll to the bottom edge.public com.badlogic.gdx.scenes.scene2d.ui.ScrollPane getScrollPane()
ScrollPane
containing getTextActor()
.public com.badlogic.gdx.scenes.scene2d.Actor getTextActor()
Actor
where the text is drawn. It may be bigger than
getScrollPane()
.public TextCellFactory getFont()
public void dispose()
protected void yScrollingCallback(boolean required)
required
- Whether y scrolling is required.protected com.badlogic.gdx.graphics.glutils.ShapeRenderer buildRenderer()
protected com.badlogic.gdx.graphics.glutils.ShapeRenderer getRenderer()
Copyright © Eben Howard 2012–2022. All rights reserved.