From 4d54758b76bee02c7f99367a21013f8b304cdbfb Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 14 Oct 2016 22:11:59 +0300 Subject: [PATCH] Keep expand ratio for last row/column when reducing grid layout size (#20297) Change-Id: Iff53a803596f4fc1eae8e4bfa307b9c1f4df961a --- .../main/java/com/vaadin/ui/GridLayout.java | 4 ++-- .../component/gridlayout/GridLayoutTest.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java index f56a90be95..e4562f81ce 100644 --- a/server/src/main/java/com/vaadin/ui/GridLayout.java +++ b/server/src/main/java/com/vaadin/ui/GridLayout.java @@ -740,7 +740,7 @@ public class GridLayout extends AbstractLayout // Forget expands for removed columns if (columns < getColumns()) { - for (int i = columns - 1; i < getColumns(); i++) { + for (int i = columns; i < getColumns(); i++) { columnExpandRatio.remove(i); getState().explicitColRatios.remove(i); } @@ -790,7 +790,7 @@ public class GridLayout extends AbstractLayout } // Forget expands for removed rows if (rows < getRows()) { - for (int i = rows - 1; i < getRows(); i++) { + for (int i = rows; i < getRows(); i++) { rowExpandRatio.remove(i); getState().explicitRowRatios.remove(i); } diff --git a/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java b/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java index 1eabf2fb62..64b466612f 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java @@ -75,6 +75,30 @@ public class GridLayoutTest { assertOrder(grid, new int[] { 0, 1, 2, 3 }); } + @Test + public void removeRowsExpandRatiosPreserved() { + GridLayout gl = new GridLayout(3, 3); + gl.setRowExpandRatio(0, 0); + gl.setRowExpandRatio(1, 1); + gl.setRowExpandRatio(2, 2); + + gl.setRows(2); + assertEquals(0, gl.getRowExpandRatio(0), 0); + assertEquals(1, gl.getRowExpandRatio(1), 0); + } + + @Test + public void removeColsExpandRatiosPreserved() { + GridLayout gl = new GridLayout(3, 3); + gl.setColumnExpandRatio(0, 0); + gl.setColumnExpandRatio(1, 1); + gl.setColumnExpandRatio(2, 2); + + gl.setColumns(2); + assertEquals(0, gl.getColumnExpandRatio(0), 0); + assertEquals(1, gl.getColumnExpandRatio(1), 0); + } + private void assertContentPositions(GridLayout grid) { assertEquals(grid.getComponentCount(), children.length); int c = 0; -- 2.39.5