Search in sources :

Example 6 with ParagraphData

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

the class DocumentRenderer method getDocumentPreferredSize.

public static Vector2i getDocumentPreferredSize(DocumentData documentData, Font defaultFont, Color defaultColor, int availableWidth) {
    DefaultDocumentRenderStyle defaultDocumentRenderStyle = new DefaultDocumentRenderStyle(defaultFont, defaultColor);
    DocumentRenderStyle documentRenderStyle = getDocumentRenderStyle(defaultDocumentRenderStyle, documentData);
    Collection<ParagraphData> paragraphs = documentData.getParagraphs();
    int minParagraphsWidth = getParagraphsMinimumWidth(availableWidth, documentRenderStyle, paragraphs);
    int documentSideMargins = documentRenderStyle.getDocumentMarginLeft().getValue(availableWidth) + documentRenderStyle.getDocumentMarginRight().getValue(availableWidth);
    int documentWidth = Math.max(availableWidth, minParagraphsWidth + documentSideMargins);
    ContainerFlowContainerRenderSpace containerRenderSpace = new ContainerFlowContainerRenderSpace(documentWidth);
    int preferredHeight = Math.max(getParagraphsPreferredHeight(documentRenderStyle, paragraphs, containerRenderSpace, 0), containerRenderSpace.getNextClearYPosition(ParagraphRenderStyle.ClearStyle.BOTH));
    int documentVerticalMargins = documentRenderStyle.getDocumentMarginTop().getValue(documentWidth) + documentRenderStyle.getDocumentMarginBottom().getValue(documentWidth);
    // Bring back the document indents to sides
    return new Vector2i(documentWidth, preferredHeight + documentVerticalMargins);
}
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) ParagraphData(org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData) Vector2i(org.joml.Vector2i) DefaultDocumentRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.DefaultDocumentRenderStyle)

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