public class TextPanel<T extends com.badlogic.gdx.graphics.Color> extends 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 TextPaneltp = 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.setKeyboardFocus(sp); stage.setScrollFocus(sp); stage.draw();
In addition to what ScrollPane
does (knobs, handling of the wheel);
this class plugs scrolling with arrow keys (up, down, page up, page down) and
vim shortcuts (j/k).
ScrollPane
Modifier and Type | Field and Description |
---|---|
T |
backgroundColor
The color to use to paint the background (outside buttons) using
ShapeRenderer . |
T |
borderColor
The color of the border around this panel, if any.
|
float |
borderSize
The size of the border, if any
|
UIUtil.CornerStyle |
borderStyle |
protected StringBuilder |
builder |
protected boolean |
distanceField |
protected com.badlogic.gdx.graphics.g2d.BitmapFont |
font |
protected squidpony.panel.IMarkup<T> |
markup |
protected com.badlogic.gdx.scenes.scene2d.ui.ScrollPane |
scrollPane |
protected TextCellFactory |
tcf |
protected List<squidpony.panel.IColoredString<T>> |
text
The text to display
|
protected com.badlogic.gdx.scenes.scene2d.Actor |
textActor
The actor whose size is adjusted to the text.
|
boolean |
vimShortcuts
Whether to use 'j' to scroll down, and 'k' to scroll up.
|
Constructor and Description |
---|
TextPanel(squidpony.panel.IMarkup<T> markup,
com.badlogic.gdx.graphics.g2d.BitmapFont font)
The text to display MUST be set later on with
init(float, float, Collection) . |
TextPanel(squidpony.panel.IMarkup<T> markup,
TextCellFactory distanceFieldFont)
The text to display MUST be set later on with
init(float, float, Collection) . |
Modifier and Type | Method and Description |
---|---|
protected String |
applyMarkup(squidpony.panel.IColoredString<T> ics) |
protected com.badlogic.gdx.graphics.glutils.ShapeRenderer |
buildRenderer() |
void |
dispose() |
void |
drawBorder(com.badlogic.gdx.graphics.g2d.Batch batch)
Draws the border.
|
com.badlogic.gdx.graphics.g2d.BitmapFont |
getFont() |
protected com.badlogic.gdx.graphics.glutils.ShapeRenderer |
getRenderer() |
com.badlogic.gdx.scenes.scene2d.ui.ScrollPane |
getScrollPane() |
com.badlogic.gdx.scenes.scene2d.Actor |
getTextActor() |
List<String> |
getTypesetText() |
void |
init(float width,
float maxHeight,
Collection<? extends squidpony.panel.IColoredString<T>> text)
This method sets the sizes of
scrollPane and textActor . |
void |
init(float width,
float maxHeight,
T color,
String... text) |
protected squidpony.panel.IColoredString<T> |
present(squidpony.panel.IColoredString<T> ics) |
void |
setFont(com.badlogic.gdx.graphics.g2d.BitmapFont font)
Sets the font to use.
|
void |
setMarkup(squidpony.panel.IMarkup<T> m) |
protected void |
yScrollingCallback(boolean required)
Callback done to do stuff according to whether y-scrolling is required
|
public T extends com.badlogic.gdx.graphics.Color backgroundColor
ShapeRenderer
. Or null
to disable background coloring.public T extends com.badlogic.gdx.graphics.Color borderColor
ShapeRenderer
and borderStyle
.public float borderSize
public UIUtil.CornerStyle borderStyle
public boolean vimShortcuts
true
.protected com.badlogic.gdx.graphics.g2d.BitmapFont font
protected boolean distanceField
protected TextCellFactory tcf
protected List<squidpony.panel.IColoredString<T extends com.badlogic.gdx.graphics.Color>> text
protected StringBuilder builder
protected final com.badlogic.gdx.scenes.scene2d.ui.ScrollPane scrollPane
protected final com.badlogic.gdx.scenes.scene2d.Actor textActor
scrollPane
.public TextPanel(squidpony.panel.IMarkup<T> markup, com.badlogic.gdx.graphics.g2d.BitmapFont font)
init(float, float, Collection)
.markup
- An optional way to compute markup.font
- The font to use. It can be set later using
setFont(BitmapFont)
, but it MUST be set before
drawing this panel.public TextPanel(squidpony.panel.IMarkup<T> markup, TextCellFactory distanceFieldFont)
init(float, float, Collection)
.markup
- An optional way to compute markup.distanceFieldFont
- A distance field font as a TextCellFactory to use.
Won't be used for drawing in cells, just the distance field code it has matters.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.public void init(float width, float maxHeight, Collection<? extends squidpony.panel.IColoredString<T>> text)
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.text
- public void drawBorder(com.badlogic.gdx.graphics.g2d.Batch batch)
batch
- public List<String> getTypesetText()
present(IColoredString)
and applyMarkup(IColoredString)
.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 com.badlogic.gdx.graphics.g2d.BitmapFont getFont()
public void dispose()
protected void yScrollingCallback(boolean required)
required
- Whether y scrolling is required.protected squidpony.panel.IColoredString<T> present(squidpony.panel.IColoredString<T> ics)
ics
- Text set when building this
filter
your
text , do it here.protected String applyMarkup(squidpony.panel.IColoredString<T> ics)
ics
- markup
.protected com.badlogic.gdx.graphics.glutils.ShapeRenderer buildRenderer()
protected com.badlogic.gdx.graphics.glutils.ShapeRenderer getRenderer()
Copyright © 2012–2016. All rights reserved.