OSDN Git Service

Ellipse for cut off labels.
authorNathanSweet <nathan.sweet@gmail.com>
Tue, 10 Sep 2013 13:56:03 +0000 (15:56 +0200)
committerNathanSweet <nathan.sweet@gmail.com>
Tue, 10 Sep 2013 13:56:03 +0000 (15:56 +0200)
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Label.java

index af3b0b8..631d873 100644 (file)
@@ -38,6 +38,7 @@ public class Label extends Widget {
        private LabelStyle style;\r
        private final TextBounds bounds = new TextBounds();\r
        private final StringBuilder text = new StringBuilder();\r
+       private StringBuilder tempText;\r
        private BitmapFontCache cache;\r
        private int labelAlign = Align.left;\r
        private HAlignment lineAlign = HAlignment.LEFT;\r
@@ -148,8 +149,20 @@ public class Label extends Widget {
                float oldScaleY = font.getScaleY();\r
                if (fontScaleX != 1 || fontScaleY != 1) font.setScale(fontScaleX, fontScaleY);\r
 \r
-               Drawable background = style.background;\r
                float width = getWidth(), height = getHeight();\r
+               StringBuilder text;\r
+               if (width < bounds.width) {\r
+                       float ellipseWidth = font.getBounds("...").width;\r
+                       text = tempText != null ? tempText : (tempText = new StringBuilder());\r
+                       text.setLength(0);\r
+                       if (width > ellipseWidth) {\r
+                               text.append(this.text, 0, font.computeVisibleGlyphs(this.text, 0, this.text.length, width - ellipseWidth));\r
+                               text.append("...");\r
+                       }\r
+               } else\r
+                       text = this.text;\r
+\r
+               Drawable background = style.background;\r
                float x = 0, y = 0;\r
                if (background != null) {\r
                        x = background.getLeftWidth();\r