Example usage for com.badlogic.gdx.graphics.g2d GlyphLayout setText

List of usage examples for com.badlogic.gdx.graphics.g2d GlyphLayout setText

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d GlyphLayout setText.

Prototype

public void setText(BitmapFont font, CharSequence str, Color color, float targetWidth, int halign,
        boolean wrap) 

Source Link

Document

Calls #setText(BitmapFont,CharSequence,int,int,Color,float,int,boolean,String) setText with the whole string and no truncation.

Usage

From source file:CB_UI_Base.GL_UI.Controls.html.HtmlView.java

License:Open Source License

private static float addTextBlog(CB_List<CB_View_Base> segmentViewList, Html_Segment_TextBlock seg,
        float innerWidth) {

    boolean markUp = !seg.hyperLinkList.isEmpty();

    BitmapFont font = FontCache.get(markUp, seg.getFontFamily(), seg.getFontStyle(), seg.getFontSize());
    GlyphLayout layout = new GlyphLayout(); // dont do this every frame!
    // Store it as member
    layout.setText(font, seg.formatedText, getColor(Color.BLACK), innerWidth - (margin * 2), Align.left, true);

    float segHeight = layout.height + (margin * 2);

    parseHyperLinks(seg, "http://");
    parseHyperLinks(seg, "www.");

    LinkLabel lbl = new LinkLabel("HtmlView" + " lbl", 0, 0, innerWidth - (margin * 2), segHeight);

    if (markUp) {
        lbl.setMarkupEnabled(true);/*from www . java 2  s. co  m*/
    }

    lbl.setTextColor(getColor(seg.getFontColor()));
    lbl.setFont(font).setHAlignment(seg.hAlignment);

    if (markUp) {
        lbl.addHyperlinks(seg.hyperLinkList);
    }

    lbl.setWrappedText(seg.formatedText);
    lbl.setUnderline(seg.underline);
    lbl.setStrikeout(seg.strikeOut);
    segmentViewList.add(lbl);

    return lbl.getHeight();
}

From source file:com.bladecoder.engineeditor.utils.Message.java

License:Apache License

private static void add(Stage stage, String text) {
    msg.clearActions();/*www. j a  v  a 2 s .  co m*/

    msg.setText(text);

    GlyphLayout textLayout = new GlyphLayout();

    textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true);

    msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2);

    if (!stage.getActors().contains(msg, true))
        stage.addActor(msg);

    msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2),
            Math.round((stage.getHeight() - msg.getHeight()) / 2));
    msg.invalidate();
}