changeset 4017:3bcb92caeb77

RT-31160: Scenegraph: error in GridPane layout with "rowspan" We expected the multispan pref width/height to be greater then the total computed size of separate cols/rows.
author Eva Krejcirova <eva.krejcirova@oracle.com>
date Thu, 20 Jun 2013 16:21:49 +0100
parents b4e20fb245b3
children 983af42d54d0
files javafx-ui-common/src/javafx/scene/layout/GridPane.java javafx-ui-common/test/unit/javafx/scene/layout/GridPaneTest.java
diffstat 2 files changed, 45 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/layout/GridPane.java	Wed Jun 19 11:40:02 2013 -0700
+++ b/javafx-ui-common/src/javafx/scene/layout/GridPane.java	Thu Jun 20 16:21:49 2013 +0100
@@ -1822,7 +1822,7 @@
                             }
                         }
                         double curLength = heights.computeTotal(interval.begin, interval.end);
-                        actualPortion = Math.min(Math.floor((ms.getValue() - curLength) / intervalRows),
+                        actualPortion = Math.min(Math.floor(Math.max(0, (ms.getValue() - curLength) / intervalRows)),
                                 actualPortion);
                     }
                 }
@@ -1858,7 +1858,7 @@
                             }
                         }
                         double curLength = heights.computeTotal(interval.begin, interval.end);
-                        actualPortion = Math.min(Math.floor((ms.getValue() - curLength) / intervalRows),
+                        actualPortion = Math.min(Math.floor(Math.max(0, (ms.getValue() - curLength) / intervalRows)),
                                 actualPortion);
                     }
                 }
@@ -1889,7 +1889,7 @@
                     final Interval interval = ms.getKey();
                     if (interval.end - 1 == i) {
                         double curLength = heights.computeTotal(interval.begin, interval.end);
-                        actualPortion = Math.min(ms.getValue() - curLength,
+                        actualPortion = Math.min(Math.max(0, ms.getValue() - curLength),
                                 actualPortion);
                     }
                 }
@@ -2048,7 +2048,7 @@
                             }
                         }
                         double curLength = widths.computeTotal(interval.begin, interval.end);
-                        actualPortion = Math.min(Math.floor((ms.getValue() - curLength) / intervalColumns),
+                        actualPortion = Math.min(Math.floor(Math.max(0, (ms.getValue() - curLength) / intervalColumns)),
                                 actualPortion);
                     }
                 }
@@ -2084,7 +2084,7 @@
                             }
                         }
                         double curLength = widths.computeTotal(interval.begin, interval.end);
-                        actualPortion = Math.min(Math.floor((ms.getValue() - curLength) / intervalColumns),
+                        actualPortion = Math.min(Math.floor(Math.max(0, (ms.getValue() - curLength) / intervalColumns)),
                                 actualPortion);
                     }
                 }
@@ -2115,7 +2115,7 @@
                     final Interval interval = ms.getKey();
                     if (interval.end - 1 == i) {
                         double curLength = widths.computeTotal(interval.begin, interval.end);
-                        actualPortion = Math.min(ms.getValue() - curLength,
+                        actualPortion = Math.min(Math.max(0, ms.getValue() - curLength),
                                 actualPortion);
                     }
                 }
--- a/javafx-ui-common/test/unit/javafx/scene/layout/GridPaneTest.java	Wed Jun 19 11:40:02 2013 -0700
+++ b/javafx-ui-common/test/unit/javafx/scene/layout/GridPaneTest.java	Thu Jun 20 16:21:49 2013 +0100
@@ -2714,4 +2714,43 @@
         assertEquals(150, child_double_34.getLayoutBounds().getHeight(), 1e-100);
     }
 
+    @Test
+    public void testGridWithSmallMultiSpanColumns() {
+        Rectangle child1 = new Rectangle(100, 100);
+        Rectangle child2 = new Rectangle(100, 100);
+
+        Rectangle child_double_12 = new Rectangle(50, 50);
+
+        gridpane.add(child1, 0, 0);
+        gridpane.add(child2, 1, 0);
+
+        gridpane.add(child_double_12, 0, 1, 2, 1);
+
+        gridpane.resize(300, 300);
+        gridpane.layout();
+
+        assertEquals(0, child1.getLayoutX(), 1e-100);
+        assertEquals(100, child2.getLayoutX(), 1e-100);
+        assertEquals(0, child_double_12.getLayoutX(), 1e-100);
+    }
+
+    @Test
+    public void testGridWithSmallMultiSpanRows() {
+        Rectangle child1 = new Rectangle(100, 100);
+        Rectangle child2 = new Rectangle(100, 100);
+
+        Rectangle child_double_12 = new Rectangle(50, 50);
+
+        gridpane.add(child1, 0, 0);
+        gridpane.add(child2, 0, 1);
+
+        gridpane.add(child_double_12, 1, 0, 1, 2);
+
+        gridpane.resize(300, 300);
+        gridpane.layout();
+
+        assertEquals(0, child1.getLayoutY(), 1e-100);
+        assertEquals(100, child2.getLayoutY(), 1e-100);
+        assertEquals(75, child_double_12.getLayoutY(), 1e-100);
+    }
 }