OSDN Git Service

[fixed] Issue 402, double newlines not rendered correctly with BitmapFontCache.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 9 Oct 2011 18:58:46 +0000 (18:58 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 9 Oct 2011 18:58:46 +0000 (18:58 +0000)
[added] Table#pack();

gdx/src/com/badlogic/gdx/graphics/g2d/BitmapFontCache.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/Table.java
tests/gdx-tests/src/com/badlogic/gdx/tests/LabelTest.java

index 4217faa..b263840 100644 (file)
@@ -338,15 +338,16 @@ public class BitmapFontCache implements Disposable {
                                        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
index f497041..65da0fb 100644 (file)
@@ -555,6 +555,13 @@ public class Table extends Group implements Layout {
                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
index 178621c..f736b7f 100644 (file)
@@ -51,21 +51,29 @@ public class LabelTest extends GdxTest {
 \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