blob: 2940ef8c6436b199ae692efa97bc716b932fa3cb (
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.ElementNode;
public class InlineLayout extends Layout {
public InlineLayout(ElementNode 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.previousSibling
.map(sibling -> sibling.location.y)
.orElseGet(() -> this.parent.location.y);
for (Layout child : this.children) {
child.layout();
this.dimension.height = Math.max(this.dimension.height, (child.location.y + child.dimension.height) - this.location.y);
this.dimension.width = Math.max(this.dimension.width, (child.location.x + child.dimension.width) - this.location.x);
}
}
}
|