aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/layout/BlockLayout.java
blob: c2ec40dc08e377a141a910de811dc8c5f2aed7dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package model.layout;

import model.html.Node;

import java.awt.*;

public class BlockLayout extends Layout {

    public BlockLayout(Node node, Layout parent) {
        super(node, parent);
    }

    public void layout() {
        this.setLocation(this.getParent().getLocation());
        this.getPreviousSibling().ifPresent(
                sibling -> this.setY(sibling.getY() + sibling.getHeight()));


        this.setDimension(this.getParent().getDimension());

        for (Layout child : this.getChildren()) {
            child.layout();
            this.setHeight(this.getHeight() + child.getHeight());
        }
    }
}