summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorDmitrii Rogozin <dmitrii@vaadin.com>2014-05-22 14:04:48 +0300
committerVaadin Code Review <review@vaadin.com>2014-06-11 11:17:29 +0000
commit3e5c5bc10752ae011ee74c82530452ba26521833 (patch)
treeee9bdad7558822525b853c331c6091e98e6e30a2 /client
parentede8fbaad050c98682df9da935caf59a3a3787c6 (diff)
downloadvaadin-framework-3e5c5bc10752ae011ee74c82530452ba26521833.tar.gz
vaadin-framework-3e5c5bc10752ae011ee74c82530452ba26521833.zip
Removes double spacing from gridLayout which has empty rows or columns (#8855)
If row has no elements or only invisible elements, its size will be set to zero. When row expand ratio was set, its size will be assigned to the value according to an expand ratio. If component takes several rows of the gridLayout, these rows are considered as non-empty and won't be removed. Change-Id: I10ddd22a6c9535b9978769bab7b496e11a28b78a
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/VGridLayout.java199
-rw-r--r--client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java11
2 files changed, 158 insertions, 52 deletions
diff --git a/client/src/com/vaadin/client/ui/VGridLayout.java b/client/src/com/vaadin/client/ui/VGridLayout.java
index 1c42243621..10e5c00a38 100644
--- a/client/src/com/vaadin/client/ui/VGridLayout.java
+++ b/client/src/com/vaadin/client/ui/VGridLayout.java
@@ -1,12 +1,12 @@
/*
* Copyright 2000-2014 Vaadin Ltd.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -19,6 +19,7 @@ package com.vaadin.client.ui;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
@@ -71,6 +72,8 @@ public class VGridLayout extends ComplexPanel {
/** For internal use only. May be removed or replaced in the future. */
public DivElement spacingMeasureElement;
+ public Set<Integer> explicitRowRatios;
+ public Set<Integer> explicitColRatios;
public VGridLayout() {
super();
@@ -92,7 +95,7 @@ public class VGridLayout extends ComplexPanel {
/**
* Returns the column widths measured in pixels
- *
+ *
* @return
*/
protected int[] getColumnWidths() {
@@ -101,7 +104,7 @@ public class VGridLayout extends ComplexPanel {
/**
* Returns the row heights measured in pixels
- *
+ *
* @return
*/
protected int[] getRowHeights() {
@@ -110,7 +113,7 @@ public class VGridLayout extends ComplexPanel {
/**
* Returns the spacing between the cells horizontally in pixels
- *
+ *
* @return
*/
protected int getHorizontalSpacing() {
@@ -119,7 +122,7 @@ public class VGridLayout extends ComplexPanel {
/**
* Returns the spacing between the cells vertically in pixels
- *
+ *
* @return
*/
protected int getVerticalSpacing() {
@@ -136,18 +139,20 @@ public class VGridLayout extends ComplexPanel {
void expandRows() {
if (!isUndefinedHeight()) {
- int usedSpace = minRowHeights[0];
- int verticalSpacing = getVerticalSpacing();
- for (int i = 1; i < minRowHeights.length; i++) {
- usedSpace += verticalSpacing + minRowHeights[i];
- }
+ int usedSpace = calcRowUsedSpace();
+ int[] actualExpandRatio = calcRowExpandRatio();
int availableSpace = LayoutManager.get(client).getInnerHeight(
getElement());
int excessSpace = availableSpace - usedSpace;
int distributed = 0;
if (excessSpace > 0) {
+ int expandRatioSum = 0;
+ for (int i = 0; i < rowHeights.length; i++) {
+ expandRatioSum += actualExpandRatio[i];
+ }
for (int i = 0; i < rowHeights.length; i++) {
- int ew = excessSpace * rowExpandRatioArray[i] / 1000;
+ int ew = excessSpace * actualExpandRatio[i]
+ / expandRatioSum;
rowHeights[i] = minRowHeights[i] + ew;
distributed += ew;
}
@@ -162,44 +167,52 @@ public class VGridLayout extends ComplexPanel {
}
}
- /** For internal use only. May be removed or replaced in the future. */
- public void updateHeight() {
- // Detect minimum heights & calculate spans
- detectRowHeights();
-
- // Expand
- expandRows();
-
- // Position
- layoutCellsVertically();
+ private int[] calcRowExpandRatio() {
+ int[] actualExpandRatio = new int[minRowHeights.length];
+ for (int i = 0; i < minRowHeights.length; i++) {
+ if (rowHasComponentsOrRowSpan(i)) {
+ actualExpandRatio[i] = rowExpandRatioArray[i];
+ } else {
+ // Should not do this if this has explicitly been
+ // expanded
+ if (explicitRowRatios.contains(i)) {
+ actualExpandRatio[i] = rowExpandRatioArray[i];
+ } else {
+ actualExpandRatio[i] = 0;
+ }
+ }
+ }
+ return actualExpandRatio;
}
- /** For internal use only. May be removed or replaced in the future. */
- public void updateWidth() {
- // Detect widths & calculate spans
- detectColWidths();
- // Expand
- expandColumns();
- // Position
- layoutCellsHorizontally();
-
+ private int calcRowUsedSpace() {
+ int usedSpace = minRowHeights[0];
+ int verticalSpacing = getVerticalSpacing();
+ for (int i = 1; i < minRowHeights.length; i++) {
+ if (rowHasComponentsOrRowSpan(i) || minRowHeights[i] > 0
+ || explicitRowRatios.contains(i)) {
+ usedSpace += verticalSpacing + minRowHeights[i];
+ }
+ }
+ return usedSpace;
}
void expandColumns() {
if (!isUndefinedWidth()) {
- int usedSpace = minColumnWidths[0];
- int horizontalSpacing = getHorizontalSpacing();
- for (int i = 1; i < minColumnWidths.length; i++) {
- usedSpace += horizontalSpacing + minColumnWidths[i];
- }
-
+ int usedSpace = calcColumnUsedSpace();
+ int[] actualExpandRatio = calcColumnExpandRatio();
int availableSpace = LayoutManager.get(client).getInnerWidth(
getElement());
int excessSpace = availableSpace - usedSpace;
int distributed = 0;
if (excessSpace > 0) {
+ int expandRatioSum = 0;
+ for (int i = 0; i < columnWidths.length; i++) {
+ expandRatioSum += actualExpandRatio[i];
+ }
for (int i = 0; i < columnWidths.length; i++) {
- int ew = excessSpace * colExpandRatioArray[i] / 1000;
+ int ew = excessSpace * actualExpandRatio[i]
+ / expandRatioSum;
columnWidths[i] = minColumnWidths[i] + ew;
distributed += ew;
}
@@ -214,6 +227,97 @@ public class VGridLayout extends ComplexPanel {
}
}
+ /**
+ * Calculates column expand ratio.
+ */
+ private int[] calcColumnExpandRatio() {
+ int[] actualExpandRatio = new int[minColumnWidths.length];
+ for (int i = 0; i < minColumnWidths.length; i++) {
+ if (colHasComponentsOrColSpan(i)) {
+ actualExpandRatio[i] = colExpandRatioArray[i];
+ } else {
+ // Should not do this if this has explicitly been
+ // expanded
+ if (explicitColRatios.contains(i)) {
+ actualExpandRatio[i] = colExpandRatioArray[i];
+ } else {
+ actualExpandRatio[i] = 0;
+ }
+ }
+ }
+ return actualExpandRatio;
+ }
+
+ /**
+ * Calculates column used space
+ */
+ private int calcColumnUsedSpace() {
+ int usedSpace = minColumnWidths[0];
+ int horizontalSpacing = getHorizontalSpacing();
+ for (int i = 1; i < minColumnWidths.length; i++) {
+ if (colHasComponentsOrColSpan(i) || minColumnWidths[i] > 0
+ || explicitColRatios.contains(i)) {
+ usedSpace += horizontalSpacing + minColumnWidths[i];
+ }
+ }
+ return usedSpace;
+ }
+
+ private boolean rowHasComponentsOrRowSpan(int i) {
+ for (Cell cell : widgetToCell.values()) {
+ if (cell.row == i) {
+ return true;
+ }
+ }
+ for (SpanList l : rowSpans) {
+ for (Cell cell : l.cells) {
+ if (cell.row >= i && i < cell.row + cell.rowspan) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean colHasComponentsOrColSpan(int i) {
+ for (Cell cell : widgetToCell.values()) {
+ if (cell.col == i) {
+ return true;
+ }
+ }
+ for (SpanList l : colSpans) {
+ for (Cell cell : l.cells) {
+ if (cell.col >= i && i < cell.col + cell.colspan) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /** For internal use only. May be removed or replaced in the future. */
+ public void updateHeight() {
+ // Detect minimum heights & calculate spans
+ detectRowHeights();
+
+ // Expand
+ expandRows();
+
+ // Position
+ layoutCellsVertically();
+ }
+
+ /** For internal use only. May be removed or replaced in the future. */
+ public void updateWidth() {
+ // Detect widths & calculate spans
+ detectColWidths();
+ // Expand
+ expandColumns();
+ // Position
+ layoutCellsHorizontally();
+
+ }
+
void layoutCellsVertically() {
int verticalSpacing = getVerticalSpacing();
LayoutManager layoutManager = LayoutManager.get(client);
@@ -241,7 +345,9 @@ public class VGridLayout extends ComplexPanel {
cell.layoutVertically(y, reservedMargin);
}
- y += rowHeights[row] + verticalSpacing;
+ if (rowHasComponentsOrRowSpan(row) || rowHeights[row] > 0) {
+ y += rowHeights[row] + verticalSpacing;
+ }
}
}
@@ -277,7 +383,9 @@ public class VGridLayout extends ComplexPanel {
cell.layoutHorizontally(x, reservedMargin);
}
}
- x += columnWidths[i] + horizontalSpacing;
+ if (colHasComponentsOrColSpan(i) || columnWidths[i] > 0) {
+ x += columnWidths[i] + horizontalSpacing;
+ }
}
if (isUndefinedWidth()) {
@@ -602,7 +710,6 @@ public class VGridLayout extends ComplexPanel {
- childComponentData.column1;
// Set cell height
rowspan = 1 + childComponentData.row2 - childComponentData.row1;
-
setAlignment(new AlignmentInfo(childComponentData.alignment));
}
@@ -644,7 +751,7 @@ public class VGridLayout extends ComplexPanel {
* Creates a new Cell with the given coordinates.
* <p>
* For internal use only. May be removed or replaced in the future.
- *
+ *
* @param row
* @param col
* @return
@@ -660,7 +767,7 @@ public class VGridLayout extends ComplexPanel {
* child component is also returned if "element" is part of its caption.
* <p>
* For internal use only. May be removed or replaced in the future.
- *
+ *
* @param element
* An element that is a nested sub element of the root element in
* this layout
@@ -681,13 +788,13 @@ public class VGridLayout extends ComplexPanel {
* child component is also returned if "element" is part of its caption.
* <p>
* For internal use only. May be removed or replaced in the future.
- *
+ *
* @param element
* An element that is a nested sub element of the root element in
* this layout
* @return The Paintable which the element is a part of. Null if the element
* belongs to the layout and not to a child.
- *
+ *
* @since 7.2
*/
public ComponentConnector getComponent(Element element) {
diff --git a/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java b/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
index 67220e5c36..786bd18bf9 100644
--- a/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
+++ b/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
@@ -1,12 +1,12 @@
/*
* Copyright 2000-2014 Vaadin Ltd.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -119,9 +119,7 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
layout.rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand");
layout.updateMarginStyleNames(new MarginInfo(getState().marginsBitmask));
-
layout.updateSpacingStyleName(getState().spacing);
-
getLayoutManager().setNeedsLayout(this);
}
@@ -171,7 +169,8 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
layout.columnWidths = new int[cols];
layout.rowHeights = new int[rows];
-
+ layout.explicitRowRatios = getState().explicitRowRatios;
+ layout.explicitColRatios = getState().explicitColRatios;
layout.setSize(rows, cols);
}