import com.badlogic.gdx.graphics.g2d.BitmapFontCache;\r
import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
import com.badlogic.gdx.scenes.scene2d.utils.Align;\r
+import com.badlogic.gdx.scenes.scene2d.utils.Drawable;\r
\r
/** A text label, with optional word wrapping.\r
* <p>\r
public void draw (SpriteBatch batch, float parentAlpha) {\r
layout();\r
validate();\r
+ if (style.background != null) {\r
+ Color color = getColor();\r
+ batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);\r
+ style.background.draw(batch, getX(), getY(), getWidth(), getHeight());\r
+ }\r
cache.setPosition(getX(), getY());\r
cache.draw(batch, getColor().a * parentAlpha);\r
}\r
public BitmapFont font;\r
/** Optional. */\r
public Color fontColor;\r
+ /** Optional. */\r
+ public Drawable background;\r
\r
public LabelStyle () {\r
}\r
}\r
\r
private final TableLayout layout;\r
- private Drawable backgroundDrawable;\r
+ private Drawable background;\r
private boolean clip;\r
private Skin skin;\r
\r
/** Called to draw the background, before clipping is applied (if enabled). Default implementation draws the background\r
* drawable. */\r
protected void drawBackground (SpriteBatch batch, float parentAlpha) {\r
- if (backgroundDrawable != null) {\r
+ if (background != null) {\r
Color color = getColor();\r
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);\r
- backgroundDrawable.draw(batch, getX(), getY(), getWidth(), getHeight());\r
+ background.draw(batch, getX(), getY(), getWidth(), getHeight());\r
}\r
}\r
\r
Rectangle tableBounds = Rectangle.tmp;\r
tableBounds.width = getWidth();\r
tableBounds.height = getHeight();\r
- if (backgroundDrawable == null) {\r
+ if (background == null) {\r
tableBounds.x = 0;\r
tableBounds.y = 0;\r
} else {\r
}\r
\r
public float getPrefWidth () {\r
- if (backgroundDrawable != null) return Math.max(layout.getPrefWidth(), backgroundDrawable.getMinWidth());\r
+ if (background != null) return Math.max(layout.getPrefWidth(), background.getMinWidth());\r
return layout.getPrefWidth();\r
}\r
\r
public float getPrefHeight () {\r
- if (backgroundDrawable != null) return Math.max(layout.getPrefHeight(), backgroundDrawable.getMinHeight());\r
+ if (background != null) return Math.max(layout.getPrefHeight(), background.getMinHeight());\r
return layout.getPrefHeight();\r
}\r
\r
* {@link Drawable#getTopHeight()}, {@link Drawable#getLeftWidth()}, and {@link Drawable#getRightWidth()}.\r
* @param background If null, the background will be cleared and all padding is removed. */\r
public void setBackground (Drawable background) {\r
- if (this.backgroundDrawable == background) return;\r
- this.backgroundDrawable = background;\r
+ if (this.background == background) return;\r
+ this.background = background;\r
if (background == null)\r
pad(null);\r
else {\r
}\r
\r
public Drawable getBackground () {\r
- return backgroundDrawable;\r
+ return background;\r
}\r
\r
/** Causes the contents to be clipped if they exceed the table widget bounds. Enabling clipping will set\r