Example usage for com.badlogic.gdx.scenes.scene2d.ui Align LEFT

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Align LEFT

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Align LEFT.

Prototype

int LEFT

To view the source code for com.badlogic.gdx.scenes.scene2d.ui Align LEFT.

Click Source Link

Usage

From source file:com.digitale.utils.Actors.java

License:Open Source License

public static Actor topToast(final String text, final float time, final Skin skin) {
    final Window window = new Window("", skin);
    final Color windowColor = new Color(1, 0, 0, 1);
    window.setMovable(false);//ww  w .  j  ava2 s.c o m

    window.defaults().spaceBottom(5);

    Label toastLabel = new Label(text, skin);
    toastLabel.setAlignment(Align.LEFT);
    toastLabel.setWrap(true);

    window.row().fillX().expandX();
    window.add(toastLabel).fillX().padLeft(10);

    window.invalidate();

    window.width = Gdx.app.getGraphics().getWidth() * 0.95f;
    window.height = toastLabel.getTextBounds().height + 20 + window.getStyle().titleFont.getLineHeight();

    window.x = Gdx.app.getGraphics().getWidth() * 0.5f - window.width * 0.5f;

    float outsideY = Gdx.app.getGraphics().getHeight() + window.height;
    float insideY = Gdx.app.getGraphics().getHeight() - window.height
            + window.getStyle().titleFont.getLineHeight();

    window.y = outsideY;

    final TimelineAnimation timelineAnimation = Builders.animation( //
            Builders.timeline() //
                    .value(Builders.timelineValue(window, Scene2dConverters.actorPositionTypeConverter) //
                            .keyFrame(0f, new float[] { window.x, outsideY }, //
                                    InterpolationFunctions.linear(), InterpolationFunctions.easeIn()) //
                            .keyFrame(1f, new float[] { window.x, insideY }) //
                            .keyFrame(4f, new float[] { window.x, insideY }, //
                                    InterpolationFunctions.linear(), InterpolationFunctions.easeOut()) //
                            .keyFrame(5f, new float[] { window.x, outsideY }) //
            ) //
    ) //
            .started(true) //
            .delay(0f) //
            .speed(5f / time) //
            .build();

    window.action(new ActionAdapter() {
        @Override
        public void act(float delta) {
            timelineAnimation.update(delta);

            if (timelineAnimation.isFinished()) {
                window.getStage().removeActor(window);
            }
        }
    });

    return window;
}

From source file:com.digitale.utils.Actors.java

License:Open Source License

public static Actor bottomToast(final String text, final float time, Skin skin) {
    skin = new Skin(Gdx.files.internal("data/dialogskin.json"), Gdx.files.internal("data/dialogskin.png"));
    final Window window = new Window("", skin);

    window.setMovable(false);/*from   w w  w.  j a va 2 s  .com*/

    window.defaults().spaceBottom(5);

    Label toastLabel = new Label(text, skin);
    toastLabel.setAlignment(Align.LEFT);
    toastLabel.setWrap(true);
    window.row().fillX().expandX();
    window.add(toastLabel).fillX().padLeft(10);

    window.invalidate();

    window.width = Gdx.graphics.getWidth() * 0.5f;
    window.height = toastLabel.getTextBounds().height * 5 + window.getStyle().titleFont.getLineHeight();

    window.x = Gdx.graphics.getWidth() * 0.5f - window.width * 0.5f;

    float outsideY = 0 - window.height;
    float insideY = -20 + window.height + window.getStyle().titleFont.getLineHeight();

    window.y = outsideY;

    final TimelineAnimation timelineAnimation = Builders.animation( //
            Builders.timeline() //
                    .value(Builders.timelineValue(window, Scene2dConverters.actorPositionTypeConverter) //
                            .keyFrame(0f, new float[] { window.x, outsideY }, //
                                    InterpolationFunctions.linear(), InterpolationFunctions.easeIn()) //
                            .keyFrame(.5f, new float[] { window.x, insideY }) //
                            .keyFrame(4f, new float[] { window.x, insideY }, //
                                    InterpolationFunctions.linear(), InterpolationFunctions.easeOut()) //
                            .keyFrame(4.5f, new float[] { window.x, outsideY }) //
            ) //
    ) //
            .started(true) //
            .delay(0f) //
            .speed(5f / time) //
            .build();

    window.action(new ActionAdapter() {
        @Override
        public void act(float delta) {
            timelineAnimation.update(delta);

            if (timelineAnimation.isFinished()) {
                window.getStage().removeActor(window);
            }
        }
    });

    return window;
}

From source file:com.digitale.utils.Actors.java

License:Open Source License

public static Actor twoOptionsDialog(String texts, final DialogListener dialogListener, String titleText,
        String firstOption, String secondOption, Skin skin) {
    Window window = new Window(titleText, skin);

    window.setMovable(false);/*from w  ww .  j  a va  2s  .  c om*/

    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);

    firstOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });

    secondOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });

    window.defaults().spaceBottom(5);
    window.row().fill().expandX();

    //for (int i = 0; i < texts.length; i++) {
    window.row().padLeft(10);
    Label label = new Label(texts, skin);
    label.setWrap(true);
    window.add(label).align(Align.LEFT).colspan(2).fillX();
    //}

    window.row().fill().expandX();
    window.add(firstOptionButton).align(Align.CENTER).padLeft(5).padRight(5).expandX();
    window.add(secondOptionButton).align(Align.CENTER).padLeft(5).padRight(5).expandX();

    FlickScrollPane scrollPane = new FlickScrollPane(window);

    //scrollPane.width = GameLoop.camera.viewportWidth * 0.5f;
    scrollPane.width = Gdx.graphics.getWidth() * 0.5f;
    scrollPane.height = Gdx.graphics.getHeight() * 0.6f;
    scrollPane.x = Gdx.graphics.getWidth() * 0.5f - scrollPane.width * 0.5f;
    scrollPane.y = Gdx.graphics.getHeight() * 0.6f - scrollPane.height * 0.6f;

    return scrollPane;
}

From source file:com.digitale.utils.Actors.java

License:Open Source License

public static Actor threeOptionsDialog(String texts, final DialogListener dialogListener, String titleText,
        String firstOption, String secondOption, String thirdOption, Skin skin) {
    Window window = new Window(titleText, skin);

    window.setMovable(true);//  w w  w  . ja  v  a  2  s.co m

    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);
    TextButton thirdOptionButton = new TextButton(thirdOption, skin);

    firstOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });

    secondOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });

    thirdOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(2);
        }
    });

    window.defaults().spaceBottom(5);
    window.row().fill().expandX();

    window.row().padLeft(5);
    Label label = new Label(texts, skin);
    label.setWrap(true);
    window.add(label).align(Align.LEFT).colspan(3).fillX();

    window.row().fill().expandX().padTop(5);
    window.add(firstOptionButton).align(Align.CENTER).padLeft(5).padRight(5);
    window.add(secondOptionButton).align(Align.CENTER).padLeft(5).padRight(5);
    window.add(thirdOptionButton).align(Align.CENTER).padLeft(5).padRight(5);

    FlickScrollPane scrollPane = new FlickScrollPane(window);

    scrollPane.width = Gdx.graphics.getWidth() * 0.5f;
    scrollPane.height = Gdx.graphics.getHeight() * 0.6f;
    scrollPane.x = Gdx.graphics.getWidth() * 0.5f - scrollPane.width * 0.5f;
    scrollPane.y = Gdx.graphics.getHeight() * 0.6f - scrollPane.height * 0.6f;

    return scrollPane;
}

From source file:com.digitale.utils.Actors.java

License:Open Source License

public static Actor MissionDialog(String texts, final DialogListener dialogListener, String titleText,
        String firstOption, String secondOption, String thirdOption, String forthOption, Skin skin) {
    Window window = new Window(titleText, skin);
    window.setFillParent(false);//w w  w  .j  a  v a 2 s.  c  o  m
    window.setMovable(true);

    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);
    TextButton thirdOptionButton = new TextButton(thirdOption, skin);
    TextButton forthOptionButton = new TextButton(forthOption, skin);
    firstOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });

    secondOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });

    thirdOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(2);
        }
    });
    forthOptionButton.setClickListener(new ClickListener() {
        @Override
        public void click(Actor actor, float x, float y) {
            dialogListener.optionSelected(3);

        }
    });
    if (Stardust3d.DEBUG)
        window.debug();
    window.defaults().spaceBottom(5);
    window.row();

    window.row().padLeft(5);
    Label label = new Label(texts, skin);
    label.setWrap(true);
    window.add(label).align(Align.LEFT).colspan(4).fillX();

    window.row().padTop(5);
    window.add(firstOptionButton).align(Align.CENTER).padLeft(5).padRight(5);
    window.add(secondOptionButton).align(Align.CENTER).padLeft(5).padRight(5);
    window.add(thirdOptionButton).align(Align.CENTER).padLeft(5).padRight(5);
    window.add(forthOptionButton).align(Align.CENTER).padLeft(5).padRight(5);
    window.pack();
    FlickScrollPane scrollPane = new FlickScrollPane(window);

    scrollPane.width = Gdx.app.getGraphics().getWidth() * 0.75f;
    scrollPane.height = Gdx.app.getGraphics().getHeight() * 0.75f;
    scrollPane.x = Gdx.app.getGraphics().getWidth() * 0.5f - scrollPane.width * 0.5f;
    scrollPane.y = Gdx.app.getGraphics().getHeight() * 0.5f - scrollPane.height * 0.5f;

    return scrollPane;
}

From source file:com.gsn.engine.template.GsnLabel.java

License:Apache License

/** @param labelAlign Aligns all the text with the label widget.
 * @param lineAlign Aligns each line of text (left, right, or center).
 * @see Align *//*  w  ww.ja  v  a 2  s . co  m*/
public void setAlignment(int labelAlign, int lineAlign) {
    this.labelAlign = labelAlign;

    if ((lineAlign & Align.LEFT) != 0)
        this.lineAlign = HAlignment.LEFT;
    else if ((lineAlign & Align.RIGHT) != 0)
        this.lineAlign = HAlignment.RIGHT;
    else
        this.lineAlign = HAlignment.CENTER;

    invalidate();
}

From source file:com.gsn.engine.template.GsnLabel.java

License:Apache License

@Override
public void layout() {
    computeBounds();/*from w ww  .  ja  v a2 s.  c om*/

    if (wrap) {
        float prefHeight = getPrefHeight();
        if (prefHeight != lastPrefHeight) {
            lastPrefHeight = prefHeight;
            invalidateHierarchy();
        }
    }

    float y;
    if ((labelAlign & Align.TOP) != 0) {
        y = cache.getFont().isFlipped() ? 0 : height - bounds.height;
        y += style.font.getDescent();
    } else if ((labelAlign & Align.BOTTOM) != 0) {
        y = cache.getFont().isFlipped() ? height - bounds.height : 0;
        y -= style.font.getDescent();
    } else
        y = (height - bounds.height) / 2;
    if (!cache.getFont().isFlipped())
        y += bounds.height;

    float x;
    if ((labelAlign & Align.LEFT) != 0)
        x = 0;
    else if ((labelAlign & Align.RIGHT) != 0) {
        x = width - bounds.width;
    } else
        x = (width - bounds.width) / 2;

    if (wrap)
        cache.setWrappedText(text, x, y, bounds.width, lineAlign);
    else
        cache.setMultiLineText(text, x, y, bounds.width, lineAlign);
}