aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/layout/InlineLayout.java
blob: 2de69d67be7c80bd4c0f94c985c02b5aaed2914d (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package model.layout;

import model.html.Node;

import java.awt.*;

// Inline layout style
public class InlineLayout extends Layout {

    private Point cursor;

    // Constructs a new InlineLayout
    public InlineLayout(Node node, Layout parent) {
        super(node, parent);
        cursor = new Point();
    }

    // MODIFIES: this
    // EFFECTS: recursively constructs the layout tree
    public void layout() {
        this.setLocation(this.getParent().getLocation());
        this.getPreviousSibling().ifPresent(
                sibling -> this.setY(sibling.getY() + sibling.getHeight()));

        this.setWidth(this.getParent().getWidth());
        this.setCursor(this.getX(), this.getY());

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

        // todo: recurse to calculate cursor
        this.setHeight(cursor.getY() - this.getY());
    }

    public void setCursor(Point cursor) {
        this.cursor = cursor;
    }

    public void setCursor(double x, double y) {
        this.cursor.setLocation(x, y);
    }
}