aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2008-10-30 06:48:58 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2008-10-30 06:48:58 +0000
commit8709db691628f3a3e6884de8c1c6574b8ad2c817 (patch)
tree077c1d515c0230d9e77925a7b905e8dbea454167 /src
parent34c8039b43ef15d3dd9e2550851374c21806ced6 (diff)
downloadvaadin-framework-8709db691628f3a3e6884de8c1c6574b8ad2c817.tar.gz
vaadin-framework-8709db691628f3a3e6884de8c1c6574b8ad2c817.zip
IGridLayout can now properly grow on child component changes, but still not shrink
svn changeset:5765/svn branch:trunk
Diffstat (limited to 'src')
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java74
1 files changed, 64 insertions, 10 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
index 63bb9f36d1..998b01824b 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
@@ -68,6 +68,7 @@ public class IGridLayout extends SimplePanel implements Paintable, Container {
setWidget(canvas);
}
+ @Override
protected Element getContainerElement() {
return margin;
}
@@ -534,22 +535,75 @@ public class IGridLayout extends SimplePanel implements Paintable, Container {
}
public boolean requestLayout(Set<Paintable> child) {
- boolean mayNeedLayout = false;
+ boolean needsLayout = false;
int offsetHeight = canvas.getOffsetHeight();
int offsetWidth = canvas.getOffsetWidth();
if ("".equals(width) || "".equals(height)) {
- mayNeedLayout = true;
- } else {
- for (Paintable paintable : child) {
- Cell cell = paintableToCell.get(paintable);
- if (!cell.hasRelativeHeight() || !cell.hasRelativeWidth()) {
- // cell sizes will only stay still if only relatively sized
- // components
- mayNeedLayout = true;
+ needsLayout = true;
+ }
+ for (Paintable paintable : child) {
+ Cell cell = paintableToCell.get(paintable);
+ if (!cell.hasRelativeHeight() || !cell.hasRelativeWidth()) {
+ // cell sizes will only stay still if only relatively sized
+ // components
+ // check if changed child affects min col widths
+ int width = cell.getWidth();
+ int allocated = columnWidths[cell.col];
+ for (int i = 1; i < cell.colspan; i++) {
+ allocated += spacingPixels + columnWidths[cell.col + i];
}
+ if (allocated < width) {
+ needsLayout = true;
+ // columnWidths needs to be expanded due colspanned cell
+ int neededExtraSpace = width - allocated;
+ int spaceForColunms = neededExtraSpace / cell.colspan;
+ for (int i = 0; i < cell.colspan; i++) {
+ int col = cell.col + i;
+ columnWidths[col] += spaceForColunms;
+ neededExtraSpace -= spaceForColunms;
+ }
+ if (neededExtraSpace > 0) {
+ for (int i = 0; i < cell.colspan; i++) {
+ int col = cell.col + i;
+ columnWidths[col] += 1;
+ neededExtraSpace -= 1;
+ if (neededExtraSpace == 0) {
+ break;
+ }
+ }
+ }
+ }
+ // check if changed child affects min row heights
+ int height = cell.getHeight();
+ allocated = rowHeights[cell.row];
+ for (int i = 1; i < cell.rowspan; i++) {
+ allocated += spacingPixels + rowHeights[cell.row + i];
+ }
+ if (allocated < height) {
+ needsLayout = true;
+ // columnWidths needs to be expanded due colspanned cell
+ int neededExtraSpace = height - allocated;
+ int spaceForColunms = neededExtraSpace / cell.rowspan;
+ for (int i = 0; i < cell.rowspan; i++) {
+ int row = cell.row + i;
+ rowHeights[row] += spaceForColunms;
+ neededExtraSpace -= spaceForColunms;
+ }
+ if (neededExtraSpace > 0) {
+ for (int i = 0; i < cell.rowspan; i++) {
+ int row = cell.row + i;
+ rowHeights[row] += 1;
+ neededExtraSpace -= 1;
+ if (neededExtraSpace == 0) {
+ break;
+ }
+ }
+ }
+ }
+
}
}
- if (mayNeedLayout) {
+ if (needsLayout) {
expandColumns();
expandRows();
layoutCells();