Search in sources :

Example 1 with ParagraphData

use of org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.

the class DocumentRenderer method getParagraphsMinimumWidth.

public static int getParagraphsMinimumWidth(int availableWidth, ParagraphRenderStyle baseParagraphRenderStyle, Collection<ParagraphData> paragraphs) {
    int minParagraphsWidth = 0;
    for (ParagraphData paragraphData : paragraphs) {
        ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseParagraphRenderStyle, paragraphData);
        int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(availableWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(availableWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(availableWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(availableWidth);
        int paragraphMinWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(availableWidth), paragraphData.getParagraphContents().getContentsMinWidth(paragraphRenderStyle));
        minParagraphsWidth = Math.max(minParagraphsWidth, paragraphSideIndent + paragraphMinWidth);
    }
    return minParagraphsWidth;
}
Also used : ParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData) FallbackParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Example 2 with ParagraphData

use of org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.

the class DocumentRenderer method renderParagraphs.

public static void renderParagraphs(Canvas canvas, ParagraphRenderable.HyperlinkRegister register, ParagraphRenderStyle baseRenderStyle, int xShift, int startY, int leftIndent, int rightIndent, Collection<ParagraphData> paragraphs, ContainerRenderSpace containerRenderSpace) {
    int containerWidth = containerRenderSpace.getContainerWidth();
    int yShift = startY;
    for (ParagraphData paragraphData : paragraphs) {
        yShift += renderParagraph(canvas, register, baseRenderStyle, xShift, leftIndent, rightIndent, containerRenderSpace, containerWidth, yShift, paragraphData);
    }
}
Also used : ParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData)

Example 3 with ParagraphData

use of org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.

the class HTMLParserTest method testParseSimpleParagraph.

@Test
public void testParseSimpleParagraph() throws IOException, SAXException, ParserConfigurationException {
    DocumentData documentData = htmlParser.parseHTMLDocument("<body><p>Text</p></body>");
    assertEquals(1, documentData.getParagraphs().size());
    ParagraphData paragraph = documentData.getParagraphs().iterator().next();
    assertTrue(paragraph instanceof FlowParagraphData);
}
Also used : DocumentData(org.terasology.engine.rendering.nui.widgets.browser.data.DocumentData) FlowParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.basic.FlowParagraphData) ParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData) FlowParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.basic.FlowParagraphData) Test(org.junit.jupiter.api.Test)

Example 4 with ParagraphData

use of org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.

the class DocumentRenderer method drawDocumentInRegion.

public static void drawDocumentInRegion(DocumentData documentData, Canvas canvas, Font defaultFont, Color defaultColor, Vector2i size, ParagraphRenderable.HyperlinkRegister register) {
    DefaultDocumentRenderStyle defaultDocumentRenderStyle = new DefaultDocumentRenderStyle(defaultFont, defaultColor);
    DocumentRenderStyle documentRenderStyle = getDocumentRenderStyle(defaultDocumentRenderStyle, documentData);
    int documentWidth = size.x;
    int documentMarginLeft = documentRenderStyle.getDocumentMarginLeft().getValue(documentWidth);
    int documentMarginRight = documentRenderStyle.getDocumentMarginRight().getValue(documentWidth);
    int documentMarginTop = documentRenderStyle.getDocumentMarginTop().getValue(documentWidth);
    Color backgroundColor = documentRenderStyle.getBackgroundColor();
    if (backgroundColor != null) {
        canvas.drawFilledRectangle(canvas.getRegion(), backgroundColor);
    }
    Collection<ParagraphData> paragraphs = documentData.getParagraphs();
    ContainerFlowContainerRenderSpace renderSpace = new ContainerFlowContainerRenderSpace(documentWidth);
    renderParagraphs(canvas, register, documentRenderStyle, documentMarginLeft, documentMarginTop, documentMarginLeft, documentMarginRight, paragraphs, renderSpace);
}
Also used : FallbackDocumentRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackDocumentRenderStyle) DefaultDocumentRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.DefaultDocumentRenderStyle) DocumentRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.DocumentRenderStyle) Color(org.terasology.nui.Color) ParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData) DefaultDocumentRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.DefaultDocumentRenderStyle)

Example 5 with ParagraphData

use of org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData in project Terasology by MovingBlocks.

the class DocumentRenderer method getParagraphsPreferredHeight.

public static int getParagraphsPreferredHeight(ParagraphRenderStyle baseRenderStyle, Collection<ParagraphData> paragraphs, ContainerRenderSpace containerRenderSpace, int yStart) {
    int containerWidth = containerRenderSpace.getContainerWidth();
    int yShift = yStart;
    for (ParagraphData paragraphData : paragraphs) {
        ParagraphRenderStyle paragraphRenderStyle = getParagraphRenderStyle(baseRenderStyle, paragraphData);
        ParagraphRenderStyle.ClearStyle clearStyle = paragraphRenderStyle.getClearStyle();
        if (clearStyle != ParagraphRenderStyle.ClearStyle.NONE) {
            yShift = Math.max(yShift, containerRenderSpace.getNextClearYPosition(clearStyle));
        }
        ParagraphRenderStyle.FloatStyle floatStyle = paragraphRenderStyle.getFloatStyle();
        if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT || floatStyle == ParagraphRenderStyle.FloatStyle.RIGHT) {
            int paragraphMinWidth = Math.max(paragraphRenderStyle.getParagraphMinimumWidth().getValue(containerWidth), paragraphData.getParagraphContents().getContentsMinWidth(paragraphRenderStyle));
            int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
            int height = paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
            height += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, 0, new ContainerFlowContainerRenderSpace(paragraphMinWidth), paragraphSideIndent);
            height += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
            if (floatStyle == ParagraphRenderStyle.FloatStyle.LEFT) {
                Rectanglei position = containerRenderSpace.addLeftFloat(yShift, paragraphMinWidth, height);
                yShift = position.minY;
            } else {
                Rectanglei position = containerRenderSpace.addRightFloat(yShift, paragraphMinWidth, height);
                yShift = position.minY;
            }
        } else {
            yShift += paragraphRenderStyle.getParagraphMarginTop().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingTop().getValue(containerWidth);
            int paragraphSideIndent = paragraphRenderStyle.getParagraphMarginLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginRight().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingLeft().getValue(containerWidth) + paragraphRenderStyle.getParagraphPaddingRight().getValue(containerWidth);
            yShift += paragraphData.getParagraphContents().getPreferredContentsHeight(paragraphRenderStyle, yShift, containerRenderSpace, paragraphSideIndent);
            yShift += paragraphRenderStyle.getParagraphPaddingBottom().getValue(containerWidth) + paragraphRenderStyle.getParagraphMarginBottom().getValue(containerWidth);
        }
    }
    return yShift - yStart;
}
Also used : ParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData) Rectanglei(org.terasology.joml.geom.Rectanglei) FallbackParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Aggregations

ParagraphData (org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData)6 DefaultDocumentRenderStyle (org.terasology.engine.rendering.nui.widgets.browser.ui.style.DefaultDocumentRenderStyle)2 DocumentRenderStyle (org.terasology.engine.rendering.nui.widgets.browser.ui.style.DocumentRenderStyle)2 FallbackDocumentRenderStyle (org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackDocumentRenderStyle)2 FallbackParagraphRenderStyle (org.terasology.engine.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle)2 ParagraphRenderStyle (org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)2 Vector2i (org.joml.Vector2i)1 Test (org.junit.jupiter.api.Test)1 DocumentData (org.terasology.engine.rendering.nui.widgets.browser.data.DocumentData)1 FlowParagraphData (org.terasology.engine.rendering.nui.widgets.browser.data.basic.FlowParagraphData)1 Rectanglei (org.terasology.joml.geom.Rectanglei)1 Color (org.terasology.nui.Color)1