aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/layout/TextLayout.java
blob: 67a07a4afd30f7ad446e5757e30f9215f823a831 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package model.layout;

import model.html.TextNode;

public class TextLayout extends Layout {

    public TextLayout(TextNode node, Layout parent) {
        super(node, parent);
    }

    // recursively construct the layout tree
    public void layout() {
        this.location.x = this.previousSibling
            .map(sibling -> sibling.location.x + sibling.dimension.width)
            .orElseGet(() -> this.parent.location.x);
        this.location.y = this.parent.location.y;

        this.dimension.height = TEXT_HEIGHT_CONSTANT;
        this.dimension.width = this.associatedNode.data().length() * TEXT_WIDTH_CONSTANT;
    }
}