Search in sources :

Example 1 with SmartFontRenderer

use of com.wynntils.core.framework.rendering.SmartFontRenderer in project Wynntils by Wynntils.

the class StringUtils method wrapTextBySize.

public static String[] wrapTextBySize(String s, int maxPixels) {
    SmartFontRenderer renderer = ScreenRenderer.fontRenderer;
    int spaceSize = renderer.getStringWidth(" ");
    String[] stringArray = s.split(" ");
    StringBuilder result = new StringBuilder();
    int length = 0;
    for (String string : stringArray) {
        String[] lines = string.split("\\\\n", -1);
        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];
            if (i > 0 || length + renderer.getStringWidth(line) >= maxPixels) {
                result.append('\n');
                length = 0;
            }
            if (line.length() > 0) {
                result.append(line).append(' ');
                length += renderer.getStringWidth(line) + spaceSize;
            }
        }
    }
    return result.toString().split("\n");
}
Also used : SmartFontRenderer(com.wynntils.core.framework.rendering.SmartFontRenderer)

Aggregations

SmartFontRenderer (com.wynntils.core.framework.rendering.SmartFontRenderer)1