Search in sources :

Example 1 with DocumentRenderStyle

use of org.terasology.engine.rendering.nui.widgets.browser.ui.style.DocumentRenderStyle 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 2 with DocumentRenderStyle

use of org.terasology.engine.rendering.nui.widgets.browser.ui.style.DocumentRenderStyle 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)2 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 Vector2i (org.joml.Vector2i)1 Color (org.terasology.nui.Color)1