aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/layout/InlineLayout.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/model/layout/InlineLayout.java')
-rw-r--r--src/main/model/layout/InlineLayout.java50
1 files changed, 9 insertions, 41 deletions
diff --git a/src/main/model/layout/InlineLayout.java b/src/main/model/layout/InlineLayout.java
index 845a717..2940ef8 100644
--- a/src/main/model/layout/InlineLayout.java
+++ b/src/main/model/layout/InlineLayout.java
@@ -1,58 +1,26 @@
package model.layout;
import model.html.ElementNode;
-import model.html.Node;
-
-import java.awt.*;
public class InlineLayout extends Layout {
- private Point cursor;
-
- public InlineLayout(Node node, Layout parent) {
+ public InlineLayout(ElementNode node, Layout parent) {
super(node, parent);
- cursor = new Point();
}
// recursively construct the layout tree
public void layout() {
- this.location = (Point) this.parent.location.clone(); // java moment
- this.previousSibling.ifPresent(
- sibling -> this.location.y = sibling.location.y + sibling.dimension.height);
-
- this.dimension.width = this.parent.dimension.width;
- this.setCursor(this.location.x, this.location.y);
-
- Node node = this.associatedNode;
- switch (node) {
- case ElementNode e -> {
- if (e.tag.equals("a")) {
- this.location.x += this.parent.dimension.width;
- }
- }
- default -> {
- if (node.data().length() > 5) {
- this.dimension.height = 20;
-// this.dimension.width = this.dimension.width + node.data().length();
- }
- }
- }
+ 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 += child.dimension.height; // fixme
+ 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);
}
-
- // todo: recurse to calculate cursor
-// this.height = cursor.location.y - this.location.y;
-// System.out.println(this.associatedNode.data() + this.location);
- }
-
- public void setCursor(Point cursor) {
- this.cursor = cursor;
- }
-
- public void setCursor(double x, double y) {
- this.cursor.setLocation(x, y);
}
}