use of com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle in project libgdx by libgdx.
the class TextButton method setStyle.
public void setStyle(ButtonStyle style) {
if (style == null)
throw new NullPointerException("style cannot be null");
if (!(style instanceof TextButtonStyle))
throw new IllegalArgumentException("style must be a TextButtonStyle.");
super.setStyle(style);
this.style = (TextButtonStyle) style;
if (label != null) {
TextButtonStyle textButtonStyle = (TextButtonStyle) style;
LabelStyle labelStyle = label.getStyle();
labelStyle.font = textButtonStyle.font;
labelStyle.fontColor = textButtonStyle.fontColor;
label.setStyle(labelStyle);
}
}
use of com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle in project libgdx by libgdx.
the class ImageTextButton method setStyle.
public void setStyle(ButtonStyle style) {
if (!(style instanceof ImageTextButtonStyle))
throw new IllegalArgumentException("style must be a ImageTextButtonStyle.");
super.setStyle(style);
this.style = (ImageTextButtonStyle) style;
if (image != null)
updateImage();
if (label != null) {
ImageTextButtonStyle textButtonStyle = (ImageTextButtonStyle) style;
LabelStyle labelStyle = label.getStyle();
labelStyle.font = textButtonStyle.font;
labelStyle.fontColor = textButtonStyle.fontColor;
label.setStyle(labelStyle);
}
}
use of com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle in project libgdx by libgdx.
the class GroupTest method create.
public void create() {
batch = new SpriteBatch();
font = new BitmapFont();
renderer = new ShapeRenderer();
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);
region = new TextureRegion(new Texture(Gdx.files.internal("data/group-debug.png")));
group2 = new TestGroup("group2");
group2.setTransform(true);
stage.addActor(group2);
group1 = new TestGroup("group1");
group1.setTransform(true);
group2.addActor(group1);
LabelStyle style = new LabelStyle();
style.font = new BitmapFont();
Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
horiz = new HorizontalGroup().pad(10, 20, 30, 40).top().space(5).reverse();
for (int i = 1; i <= 15; i++) {
horiz.addActor(new Label(i + ",", style));
if (i == 7)
horiz.addActor(new Container(new Image(texture)).size(10));
}
horiz.addActor(new Container(new Image(texture)).fill().prefSize(30));
horiz.debug();
horiz.setPosition(10, 10);
horiz.pack();
stage.addActor(horiz);
horizWrap = new HorizontalGroup().wrap().pad(10, 20, 30, 40).right().rowBottom().space(5).wrapSpace(15).reverse();
for (int i = 1; i <= 15; i++) {
horizWrap.addActor(new Label(i + ",", style));
if (i == 7)
horizWrap.addActor(new Container(new Image(texture)).prefSize(10).fill());
}
horizWrap.addActor(new Container(new Image(texture)).prefSize(30));
horizWrap.debug();
horizWrap.setBounds(10, 85, 150, 40);
stage.addActor(horizWrap);
vert = new VerticalGroup().pad(10, 20, 30, 40).top().space(5).reverse();
for (int i = 1; i <= 8; i++) {
vert.addActor(new Label(i + ",", style));
if (i == 4)
vert.addActor(new Container(new Image(texture)).size(10));
}
vert.addActor(new Container(new Image(texture)).size(30));
vert.debug();
vert.setPosition(515, 10);
vert.pack();
stage.addActor(vert);
vertWrap = new VerticalGroup().wrap().pad(10, 20, 30, 40).bottom().columnRight().space(5).wrapSpace(15).reverse();
for (int i = 1; i <= 8; i++) {
vertWrap.addActor(new Label(i + ",", style));
if (i == 4)
vertWrap.addActor(new Container(new Image(texture)).prefSize(10).fill());
}
vertWrap.addActor(new Container(new Image(texture)).prefSize(30));
vertWrap.debug();
vertWrap.setBounds(610, 10, 150, 40);
stage.addActor(vertWrap);
}
use of com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle in project libgdx by libgdx.
the class DragAndDropTest method create.
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
final Skin skin = new Skin();
skin.add("default", new LabelStyle(new BitmapFont(), Color.WHITE));
skin.add("badlogic", new Texture("data/badlogic.jpg"));
Image sourceImage = new Image(skin, "badlogic");
sourceImage.setBounds(50, 125, 100, 100);
stage.addActor(sourceImage);
Image validTargetImage = new Image(skin, "badlogic");
validTargetImage.setBounds(200, 50, 100, 100);
stage.addActor(validTargetImage);
Image invalidTargetImage = new Image(skin, "badlogic");
invalidTargetImage.setBounds(200, 200, 100, 100);
stage.addActor(invalidTargetImage);
DragAndDrop dragAndDrop = new DragAndDrop();
dragAndDrop.addSource(new Source(sourceImage) {
public Payload dragStart(InputEvent event, float x, float y, int pointer) {
Payload payload = new Payload();
payload.setObject("Some payload!");
payload.setDragActor(new Label("Some payload!", skin));
Label validLabel = new Label("Some payload!", skin);
validLabel.setColor(0, 1, 0, 1);
payload.setValidDragActor(validLabel);
Label invalidLabel = new Label("Some payload!", skin);
invalidLabel.setColor(1, 0, 0, 1);
payload.setInvalidDragActor(invalidLabel);
return payload;
}
});
dragAndDrop.addTarget(new Target(validTargetImage) {
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
getActor().setColor(Color.GREEN);
return true;
}
public void reset(Source source, Payload payload) {
getActor().setColor(Color.WHITE);
}
public void drop(Source source, Payload payload, float x, float y, int pointer) {
System.out.println("Accepted: " + payload.getObject() + " " + x + ", " + y);
}
});
dragAndDrop.addTarget(new Target(invalidTargetImage) {
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
getActor().setColor(Color.RED);
return false;
}
public void reset(Source source, Payload payload) {
getActor().setColor(Color.WHITE);
}
public void drop(Source source, Payload payload, float x, float y, int pointer) {
}
});
}
use of com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle in project gdx-skineditor by cobolfoo.
the class Tooltips method showTooltip.
public void showTooltip(Actor actor) {
Vector2 v = new Vector2();
actor.localToStageCoordinates(v);
if (tooltip == null) {
LabelStyle style = new LabelStyle();
style.font = tooltipStyle.font;
style.background = tooltipStyle.background;
style.fontColor = tooltipStyle.fontColor;
tooltip = new Label(tooltips.get(actor), style);
tooltip.setStyle(style);
tooltip.pack();
tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15);
tooltip.setOriginY(tooltip.getPrefHeight());
tooltip.setColor(1, 1, 1, 0);
tooltip.setScale(1, 0);
tooltip.addAction(parallel(fadeIn(0.15f), scaleTo(1, 1, 0.15f)));
} else {
tooltip.setText(tooltips.get(actor));
tooltip.pack();
tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15);
}
stage.addActor(tooltip);
}
Aggregations