lineEnd--;\r
}\r
}\r
- if (lineEnd == start) lineEnd++;\r
- float xOffset = 0;\r
- if (alignment != HAlignment.LEFT) {\r
- float lineWidth = font.getBounds(str, start, lineEnd).width;\r
- xOffset = wrapWidth - lineWidth;\r
- if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ if (lineEnd > start) {\r
+ float xOffset = 0;\r
+ if (alignment != HAlignment.LEFT) {\r
+ float lineWidth = font.getBounds(str, start, lineEnd).width;\r
+ xOffset = wrapWidth - lineWidth;\r
+ if (alignment == HAlignment.CENTER) xOffset /= 2;\r
+ }\r
+ float lineWidth = addToCache(str, x + xOffset, y, start, lineEnd);\r
+ maxWidth = Math.max(maxWidth, lineWidth);\r
}\r
- float lineWidth = addToCache(str, x + xOffset, y, start, lineEnd);\r
- maxWidth = Math.max(maxWidth, lineWidth);\r
start = lineEnd + 1;\r
y += down;\r
numLines++;\r
return layout.getAlign();\r
}\r
\r
+ /** Sizes this table to its preferred width and height. */\r
+ public void pack () {\r
+ width = getPrefWidth();\r
+ height = getPrefHeight();\r
+ invalidate();\r
+ }\r
+\r
/** Draws the debug lines for all TableLayouts in the stage. If this method is not called each frame, no debug lines will be\r
* drawn. */\r
static public void drawDebug (Stage stage) {\r
\r
Table table = new Table();\r
stage.addActor(table);\r
- table.x = table.y = 300;\r
+ table.x = 200;\r
+ table.y = 65;\r
\r
table.debug();\r
table.add(new Label("This is regular text.", skin));\r
table.row();\r
table.add(new Label("This is regular text\nwith a newline.", skin));\r
table.row();\r
- Label label3 = new Label("This is regular text\nwith a newline,\naligned bottom, right.", skin);\r
+ Label label3 = new Label("This is regular text\n\nwith newlines,\naligned bottom, right.", skin);\r
label3.setAlignment(Align.BOTTOM | Align.RIGHT);\r
- table.add(label3).minWidth(200).minHeight(100).fill();\r
+ table.add(label3).minWidth(200).minHeight(110).fill();\r
table.row();\r
Label label4 = new Label("This is regular text with NO newlines, wrap enabled and aligned bottom, right.", skin);\r
label4.setWrap(true);\r
label4.setAlignment(Align.BOTTOM | Align.RIGHT);\r
- table.add(label4).minWidth(200).minHeight(100).fill();\r
+ table.add(label4).minWidth(200).minHeight(110).fill();\r
+ table.row();\r
+ Label label5 = new Label("This is regular text with\n\nnewlines, wrap\nenabled and aligned bottom, right.", skin);\r
+ label5.setWrap(true);\r
+ label5.setAlignment(Align.BOTTOM | Align.RIGHT);\r
+ table.add(label5).minWidth(200).minHeight(110).fill();\r
+\r
+ table.pack();\r
}\r
\r
@Override\r