summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-05-11 22:47:07 +0300
committerVaadin Code Review <review@vaadin.com>2016-05-16 09:51:09 +0000
commit7d2d091ecbb0b995dc46074725eabb456609cdf3 (patch)
tree90e89cb767f919f82e6e062404a437c0e3055790 /client
parente386748dbc487d264caae0c98bcf5cffbe43d4a2 (diff)
downloadvaadin-framework-7d2d091ecbb0b995dc46074725eabb456609cdf3.tar.gz
vaadin-framework-7d2d091ecbb0b995dc46074725eabb456609cdf3.zip
Eliminate rounding errors for GridLayout expand ratios (#19797)
Change-Id: Idf05dde5d6526fafee618fd3e2eb1afa63fab7bc
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VGridLayout.java32
-rw-r--r--client/src/main/java/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java4
2 files changed, 17 insertions, 19 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VGridLayout.java b/client/src/main/java/com/vaadin/client/ui/VGridLayout.java
index 42bcb5060a..9e13bb7fb2 100644
--- a/client/src/main/java/com/vaadin/client/ui/VGridLayout.java
+++ b/client/src/main/java/com/vaadin/client/ui/VGridLayout.java
@@ -61,10 +61,10 @@ public class VGridLayout extends ComplexPanel {
public int[] rowHeights;
/** For internal use only. May be removed or replaced in the future. */
- public int[] colExpandRatioArray;
+ public float[] colExpandRatioArray;
/** For internal use only. May be removed or replaced in the future. */
- public int[] rowExpandRatioArray;
+ public float[] rowExpandRatioArray;
int[] minColumnWidths;
@@ -142,7 +142,7 @@ public class VGridLayout extends ComplexPanel {
void expandRows() {
if (!isUndefinedHeight()) {
int usedSpace = calcRowUsedSpace();
- int[] actualExpandRatio = calcRowExpandRatio();
+ float[] actualExpandRatio = calcRowExpandRatio();
// Round down to avoid problems with fractions (100.1px available ->
// can use 100, not 101)
int availableSpace = (int) LayoutManager.get(client)
@@ -150,13 +150,12 @@ public class VGridLayout extends ComplexPanel {
int excessSpace = availableSpace - usedSpace;
int distributed = 0;
if (excessSpace > 0) {
- int expandRatioSum = 0;
+ float expandRatioSum = 0;
for (int i = 0; i < rowHeights.length; i++) {
expandRatioSum += actualExpandRatio[i];
}
for (int i = 0; i < rowHeights.length; i++) {
- int ew = excessSpace * actualExpandRatio[i]
- / expandRatioSum;
+ int ew = (int) (excessSpace * actualExpandRatio[i] / expandRatioSum);
rowHeights[i] = minRowHeights[i] + ew;
distributed += ew;
}
@@ -171,8 +170,8 @@ public class VGridLayout extends ComplexPanel {
}
}
- private int[] calcRowExpandRatio() {
- int[] actualExpandRatio = new int[minRowHeights.length];
+ private float[] calcRowExpandRatio() {
+ float[] actualExpandRatio = new float[minRowHeights.length];
for (int i = 0; i < minRowHeights.length; i++) {
if (hiddenEmptyRow(i)) {
actualExpandRatio[i] = 0;
@@ -224,7 +223,7 @@ public class VGridLayout extends ComplexPanel {
void expandColumns() {
if (!isUndefinedWidth()) {
int usedSpace = calcColumnUsedSpace();
- int[] actualExpandRatio = calcColumnExpandRatio();
+ float[] actualExpandRatio = calcColumnExpandRatio();
// Round down to avoid problems with fractions (100.1px available ->
// can use 100, not 101)
int availableSpace = (int) LayoutManager.get(client)
@@ -232,13 +231,12 @@ public class VGridLayout extends ComplexPanel {
int excessSpace = availableSpace - usedSpace;
int distributed = 0;
if (excessSpace > 0) {
- int expandRatioSum = 0;
+ float expandRatioSum = 0;
for (int i = 0; i < columnWidths.length; i++) {
expandRatioSum += actualExpandRatio[i];
}
for (int i = 0; i < columnWidths.length; i++) {
- int ew = excessSpace * actualExpandRatio[i]
- / expandRatioSum;
+ int ew = (int) (excessSpace * actualExpandRatio[i] / expandRatioSum);
columnWidths[i] = minColumnWidths[i] + ew;
distributed += ew;
}
@@ -256,8 +254,8 @@ public class VGridLayout extends ComplexPanel {
/**
* Calculates column expand ratio.
*/
- private int[] calcColumnExpandRatio() {
- int[] actualExpandRatio = new int[minColumnWidths.length];
+ private float[] calcColumnExpandRatio() {
+ float[] actualExpandRatio = new float[minColumnWidths.length];
for (int i = 0; i < minColumnWidths.length; i++) {
if (!hiddenEmptyColumn(i)) {
actualExpandRatio[i] = colExpandRatioArray[i];
@@ -537,7 +535,7 @@ public class VGridLayout extends ComplexPanel {
private static void distributeSpanSize(int[] dimensions,
int spanStartIndex, int spanSize, int spacingSize, int size,
- int[] expansionRatios) {
+ float[] expansionRatios) {
int allocated = dimensions[spanStartIndex];
for (int i = 1; i < spanSize; i++) {
allocated += spacingSize + dimensions[spanStartIndex + i];
@@ -563,8 +561,8 @@ public class VGridLayout extends ComplexPanel {
// expansion ratios
expansion = neededExtraSpace / spanSize;
} else {
- expansion = neededExtraSpace * expansionRatios[itemIndex]
- / totalExpansion;
+ expansion = (int) (neededExtraSpace
+ * expansionRatios[itemIndex] / totalExpansion);
}
dimensions[itemIndex] += expansion;
allocatedExtraSpace += expansion;
diff --git a/client/src/main/java/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java b/client/src/main/java/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
index 4d1ce692ad..b450092d54 100644
--- a/client/src/main/java/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
@@ -117,8 +117,8 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
cell.updateCell(childComponentData);
}
- layout.colExpandRatioArray = uidl.getIntArrayAttribute("colExpand");
- layout.rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand");
+ layout.colExpandRatioArray = getState().colExpand;
+ layout.rowExpandRatioArray = getState().rowExpand;
layout.updateMarginStyleNames(new MarginInfo(getState().marginsBitmask));
layout.updateSpacingStyleName(getState().spacing);