Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-03-31 06:42:53 -0400
committerFlorian Thienel2016-03-31 06:42:53 -0400
commitf764103a3b7eca808dd3f7f57d8e400416974abd (patch)
tree70ee4071406de3370a251b76c955b34e35c959f8
parentdcefc01f19bef58e6a91255565a42f79c91e40d8 (diff)
downloadorg.eclipse.mylyn.docs.vex-f764103a3b7eca808dd3f7f57d8e400416974abd.tar.gz
org.eclipse.mylyn.docs.vex-f764103a3b7eca808dd3f7f57d8e400416974abd.tar.xz
org.eclipse.mylyn.docs.vex-f764103a3b7eca808dd3f7f57d8e400416974abd.zip
layout cells in a row
Signed-off-by: Florian Thienel <florian@thienel.org>
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java19
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java56
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java3
3 files changed, 74 insertions, 4 deletions
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
index 8f685288..23d2fdad 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
@@ -29,6 +29,9 @@ public class TableCell extends BaseBox implements IStructuralBox, IParentBox<ISt
private int height;
private final ArrayList<IStructuralBox> children = new ArrayList<IStructuralBox>();
+ private int startColumn;
+ private int endColumn;
+
@Override
public void setParent(final IBox parent) {
this.parent = parent;
@@ -138,6 +141,22 @@ public class TableCell extends BaseBox implements IStructuralBox, IParentBox<ISt
return children;
}
+ public int getStartColumn() {
+ return startColumn;
+ }
+
+ public void setStartColumn(final int startColumn) {
+ this.startColumn = startColumn;
+ }
+
+ public int getEndColumn() {
+ return endColumn;
+ }
+
+ public void setEndColumn(final int endColumn) {
+ this.endColumn = endColumn;
+ }
+
public void layout(final Graphics graphics) {
height = 0;
for (int i = 0; i < children.size(); i += 1) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java
index fe4d5887..2660eef7 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableRow.java
@@ -140,13 +140,63 @@ public class TableRow extends BaseBox implements IStructuralBox, IParentBox<IStr
public void layout(final Graphics graphics) {
height = 0;
+ int columnIndex = 1;
for (int i = 0; i < children.size(); i += 1) {
final IStructuralBox child = children.get(i);
- child.setPosition(height, 0);
- child.setWidth(width);
+
+ final int startColumn = getStartColumn(child, columnIndex);
+ final int endColumn = getEndColumn(child, startColumn);
+
+ final int childLeft = getColumnWidth(1, startColumn - 1);
+ final int columnWidth = getColumnWidth(startColumn, endColumn);
+
+ child.setPosition(0, childLeft);
+ child.setWidth(columnWidth);
child.layout(graphics);
- height += child.getHeight();
+ height = Math.max(height, child.getHeight());
+ columnIndex = endColumn + 1;
+ }
+ }
+
+ private int getColumnWidth(final int startIndex, final int endIndex) {
+ int columnWidth = 0;
+ for (int i = startIndex; i <= endIndex; i += 1) {
+ columnWidth += getColumnWidth(i);
+ }
+ return columnWidth;
+ }
+
+ private int getColumnWidth(final int index) {
+ if (index < 1 || index > children.size()) {
+ return 0;
+ }
+ return Math.round(width / children.size());
+ }
+
+ private static int getStartColumn(final IStructuralBox box, final int defaultColumn) {
+ final int boxStartColumn = box.accept(new BaseBoxVisitorWithResult<Integer>(0) {
+ @Override
+ public Integer visit(final TableCell box) {
+ return box.getStartColumn();
+ }
+ });
+ if (boxStartColumn > 0) {
+ return boxStartColumn;
+ }
+ return defaultColumn;
+ }
+
+ private static int getEndColumn(final IStructuralBox box, final int defaultColumn) {
+ final int boxEndColumn = box.accept(new BaseBoxVisitorWithResult<Integer>(0) {
+ @Override
+ public Integer visit(final TableCell box) {
+ return box.getEndColumn();
+ }
+ });
+ if (boxEndColumn > 0) {
+ return boxEndColumn;
}
+ return defaultColumn;
}
@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
index 0fadc44d..8d05098f 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
@@ -250,7 +250,8 @@ public class CssBasedBoxModelBuilder implements IBoxModelBuilder {
}
private IStructuralBox visualizeAsTableRow(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
- return tableRow(visualizeAsBlock(element, styles, childrenResults));
+ final IStructuralBox content = visualizeChildrenAsStructure(element, styles, childrenResults, tableRow());
+ return wrapUpStructuralElementContent(element, styles, childrenResults, content);
}
private IStructuralBox visualizeAsTableCell(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {

Back to the top