Search in sources :

Example 6 with ParagraphData

use of org.terasology.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) {
                Rect2i position = containerRenderSpace.addLeftFloat(yShift, paragraphMinWidth, height);
                yShift = position.minY();
            } else {
                Rect2i 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 : Rect2i(org.terasology.math.geom.Rect2i) ParagraphData(org.terasology.rendering.nui.widgets.browser.data.ParagraphData) FallbackParagraphRenderStyle(org.terasology.rendering.nui.widgets.browser.ui.style.FallbackParagraphRenderStyle) ParagraphRenderStyle(org.terasology.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Aggregations

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