package com.brackeen.app.view;

import com.brackeen.app.BitmapFont;
import java.awt.Graphics2D;

@SuppressWarnings("unused")
public class Label extends View {
    
    private BitmapFont font;
    private String text;
    
    public Label() {
        
    }
    
    public Label(BitmapFont font, String text) {
        this.font = font;
        this.text = text;
        sizeToFit();
    }

    public BitmapFont getFont() {
        return font;
    }

    public void setFont(BitmapFont font) {
        this.font = font;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
    
    @Override
    public void sizeToFit() {
        if (font == null) {
            setSize(0, 0);
        }
        else {
            setSize(font.getStringWidth(text), font.getHeight());
        }
    }
    
    @Override
    public void onDraw(Graphics2D g) {
        if (font != null) {
            font.drawString(g, text);
        }
    }
}

@@ -1004,10 +1004,831 @@
 %7D%0A    %7D%0A
+    %0A    public static View makeMultilineLabel(BitmapFont font, String text, float anchorX) %7B%0A        View view = new View();%0A        int y = 0;%0A        int index = 0;%0A        while (true) %7B%0A            String line;%0A            int newIndex = text.indexOf('%5Cn', index);%0A            if (newIndex == -1) %7B%0A                line = text.substring(index);%0A            %7D else %7B%0A                line = text.substring(index, newIndex);%0A            %7D%0A            Label label = new Label(font, line);%0A            label.setLocation(0, y);%0A            label.setAnchor(anchorX, 0);%0A            view.addSubview(label);%0A            y += font.getHeight();%0A            %0A            if (newIndex == -1) %7B%0A                break;%0A            %7D%0A            index = newIndex + 1;%0A        %7D%0A        view.setHeight(y);%0A        return view;%0A    %7D%0A
 %7D%0A

Add method for multiline labels