diff options
author | Artur Signell <artur@vaadin.com> | 2016-05-11 22:47:07 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-05-16 09:51:09 +0000 |
commit | 7d2d091ecbb0b995dc46074725eabb456609cdf3 (patch) | |
tree | 90e89cb767f919f82e6e062404a437c0e3055790 /server | |
parent | e386748dbc487d264caae0c98bcf5cffbe43d4a2 (diff) | |
download | vaadin-framework-7d2d091ecbb0b995dc46074725eabb456609cdf3.tar.gz vaadin-framework-7d2d091ecbb0b995dc46074725eabb456609cdf3.zip |
Eliminate rounding errors for GridLayout expand ratios (#19797)
Change-Id: Idf05dde5d6526fafee618fd3e2eb1afa63fab7bc
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/GridLayout.java | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java index 3b9272b034..214d0c567f 100644 --- a/server/src/main/java/com/vaadin/ui/GridLayout.java +++ b/server/src/main/java/com/vaadin/ui/GridLayout.java @@ -461,58 +461,38 @@ public class GridLayout extends AbstractLayout implements */ @Override public void paintContent(PaintTarget target) throws PaintException { - final Integer[] columnExpandRatioArray = new Integer[getColumns()]; - final Integer[] rowExpandRatioArray = new Integer[getRows()]; + // TODO Remove once LegacyComponent is no longer implemented + } - int realColExpandRatioSum = 0; + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); + + getState().colExpand = new float[getColumns()]; float colSum = getExpandRatioSum(columnExpandRatio); if (colSum == 0) { - // no columns has been expanded, all cols have same expand - // rate - float equalSize = 1 / (float) getColumns(); - int myRatio = Math.round(equalSize * 1000); + // no cols have been expanded for (int i = 0; i < getColumns(); i++) { - columnExpandRatioArray[i] = myRatio; + getState().colExpand[i] = 1f; } - realColExpandRatioSum = myRatio * getColumns(); } else { for (int i = 0; i < getColumns(); i++) { - int myRatio = Math - .round((getColumnExpandRatio(i) / colSum) * 1000); - columnExpandRatioArray[i] = myRatio; - realColExpandRatioSum += myRatio; + getState().colExpand[i] = getColumnExpandRatio(i); } } - int realRowExpandRatioSum = 0; + getState().rowExpand = new float[getRows()]; float rowSum = getExpandRatioSum(rowExpandRatio); if (rowSum == 0) { // no rows have been expanded - float equalSize = 1 / (float) getRows(); - int myRatio = Math.round(equalSize * 1000); for (int i = 0; i < getRows(); i++) { - rowExpandRatioArray[i] = myRatio; + getState().rowExpand[i] = 1f; } - realRowExpandRatioSum = myRatio * getRows(); } else { - for (int cury = 0; cury < getRows(); cury++) { - int myRatio = Math - .round((getRowExpandRatio(cury) / rowSum) * 1000); - rowExpandRatioArray[cury] = myRatio; - realRowExpandRatioSum += myRatio; + for (int i = 0; i < getRows(); i++) { + getState().rowExpand[i] = getRowExpandRatio(i); } } - // correct possible rounding error - if (rowExpandRatioArray.length > 0) { - rowExpandRatioArray[0] -= realRowExpandRatioSum - 1000; - } - if (columnExpandRatioArray.length > 0) { - columnExpandRatioArray[0] -= realColExpandRatioSum - 1000; - } - target.addAttribute("colExpand", columnExpandRatioArray); - target.addAttribute("rowExpand", rowExpandRatioArray); - } private float getExpandRatioSum(Map<Integer, Float> ratioMap) { |