diff options
Diffstat (limited to 'src/main/model/layout/InlineLayout.java')
-rw-r--r-- | src/main/model/layout/InlineLayout.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/model/layout/InlineLayout.java b/src/main/model/layout/InlineLayout.java new file mode 100644 index 0000000..219b863 --- /dev/null +++ b/src/main/model/layout/InlineLayout.java @@ -0,0 +1,39 @@ +package model.layout; + +import model.html.Node; + +import java.awt.*; + +public class InlineLayout extends Layout { + + private Point cursor; + + public InlineLayout(Node node, Layout parent) { + super(node, parent); + cursor = new Point(); + } + + 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); + } +} |