changeset 5984:1332ba0d7f6a

RT-34849 : AnchorPane doesn't fully respect min size of it's children in certain cases
author Martin Sladecek <martin.sladecek@oracle.com>
date Fri, 13 Dec 2013 13:43:12 +0100
parents 1fe2a517b2cc
children 8a5c6817206d
files modules/graphics/src/main/java/javafx/scene/layout/AnchorPane.java modules/graphics/src/test/java/javafx/scene/layout/AnchorPaneTest.java
diffstat 2 files changed, 94 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/layout/AnchorPane.java	Thu Dec 12 17:44:42 2013 -0800
+++ b/modules/graphics/src/main/java/javafx/scene/layout/AnchorPane.java	Fri Dec 13 13:43:12 2013 +0100
@@ -271,7 +271,7 @@
                 childHeight = computeChildHeight(child, getTopAnchor(child), getBottomAnchor(child), contentHeight, -1);
             }
             max = Math.max(max, left + (minimum && leftAnchor != null && rightAnchor != null?
-                    child.minWidth(childHeight) : child.prefWidth(childHeight)) + right);
+                    child.minWidth(childHeight) : computeChildPrefAreaWidth(child, -1, null, childHeight, false)) + right);
         }
 
         final Insets insets = getInsets();
@@ -294,7 +294,7 @@
                 childWidth = computeChildWidth(child, getLeftAnchor(child), getRightAnchor(child), contentWidth, -1);
             }
             max = Math.max(max, top + (minimum && topAnchor != null && bottomAnchor != null?
-                    child.minHeight(childWidth) : child.prefHeight(childWidth)) + bottom);
+                    child.minHeight(childWidth) : computeChildPrefAreaHeight(child, -1, null, childWidth)) + bottom);
         }
 
         final Insets insets = getInsets();
--- a/modules/graphics/src/test/java/javafx/scene/layout/AnchorPaneTest.java	Thu Dec 12 17:44:42 2013 -0800
+++ b/modules/graphics/src/test/java/javafx/scene/layout/AnchorPaneTest.java	Fri Dec 13 13:43:12 2013 +0100
@@ -623,4 +623,96 @@
         assertEquals(30, internalAnchorpane.prefWidth(-1), 1e-100);
         assertEquals(256, internalAnchorpane.prefHeight(-1), 1e-100);
     }
+    
+    @Test
+    public void testTopAnchoredMinSizeOverridden() {
+        AnchorPane anchorpane = new AnchorPane();
+        MockResizable child = new MockResizable(300, 400, 100, 100, 500, 600);
+        anchorpane.setTopAnchor(child, 10.0);
+        anchorpane.getChildren().add(child);
+
+        assertEquals(300, anchorpane.minWidth(-1), 1e-100); // Not restricted, at pref. width
+        assertEquals(410, anchorpane.minHeight(-1), 1e-100); // Not restricted, at pref. height
+        assertEquals(300, anchorpane.prefWidth(-1), 1e-100);
+        assertEquals(410, anchorpane.prefHeight(-1), 1e-100);
+
+        anchorpane.autosize();
+        anchorpane.layout();
+        assertEquals(0, child.getLayoutX(), 1e-100);
+        assertEquals(10, child.getLayoutY(), 1e-100);
+        assertEquals(300, child.getWidth(), 1e-100);
+        assertEquals(400, child.getHeight(), 1e-100);
+    }
+    
+    @Test
+    public void testBottomAnchoredMinSizeOverridden() {
+        AnchorPane anchorpane = new AnchorPane();
+        MockResizable child = new MockResizable(300,400, 100,100, 500,600);
+        anchorpane.setBottomAnchor(child, 10.0);
+        anchorpane.getChildren().add(child);
+
+        assertEquals(300, anchorpane.minWidth(-1), 1e-100); // Not restricted, at pref. width
+        assertEquals(410, anchorpane.minHeight(-1), 1e-100); // Not restricted, at pref. height
+        assertEquals(300, anchorpane.prefWidth(-1), 1e-100);
+        assertEquals(410, anchorpane.prefHeight(-1), 1e-100);
+
+        anchorpane.autosize();
+        anchorpane.layout();
+        assertEquals(0, child.getLayoutX(), 1e-100);
+        assertEquals(0, child.getLayoutY(), 1e-100);
+        assertEquals(300, child.getWidth(), 1e-100);
+        assertEquals(400, child.getHeight(), 1e-100);
+    }
+    
+    @Test public void testLeftAnchoredMinSizeOverridden() {
+        AnchorPane anchorpane = new AnchorPane();
+        MockResizable child = new MockResizable(300,400, 100,100, 500,600);
+        anchorpane.setLeftAnchor(child, 10.0);
+        anchorpane.getChildren().add(child);
+
+        assertEquals(310, anchorpane.minWidth(-1), 1e-100); // Not restricted, at pref. width
+        assertEquals(400, anchorpane.minHeight(-1), 1e-100); // Not restricted, at pref. height
+        assertEquals(310, anchorpane.prefWidth(-1), 1e-100);
+        assertEquals(400, anchorpane.prefHeight(-1), 1e-100);
+
+        anchorpane.autosize();
+        anchorpane.layout();
+        assertEquals(10, child.getLayoutX(), 1e-100);
+        assertEquals(0, child.getLayoutY(), 1e-100);
+        assertEquals(300, child.getWidth(), 1e-100);
+        assertEquals(400, child.getHeight(), 1e-100);
+
+        anchorpane.resize(500,500);
+        anchorpane.layout();
+        assertEquals(10, child.getLayoutX(), 1e-100);
+        assertEquals(0, child.getLayoutY(), 1e-100);
+        assertEquals(300, child.getWidth(), 1e-100);
+        assertEquals(400, child.getHeight(), 1e-100);
+    }
+    
+    @Test public void testRightAnchoredMinSizeOverridden() {
+        AnchorPane anchorpane = new AnchorPane();
+        MockResizable child = new MockResizable(300,400, 100,100, 500,600);
+        anchorpane.setRightAnchor(child, 10.0);
+        anchorpane.getChildren().add(child);
+
+        assertEquals(310, anchorpane.minWidth(-1), 1e-100); // Not restricted, at pref. width
+        assertEquals(400, anchorpane.minHeight(-1), 1e-100); // Not restricted, at pref. height
+        assertEquals(310, anchorpane.prefWidth(-1), 1e-100);
+        assertEquals(400, anchorpane.prefHeight(-1), 1e-100);
+
+        anchorpane.autosize();
+        anchorpane.layout();
+        assertEquals(0, child.getLayoutX(), 1e-100);
+        assertEquals(0, child.getLayoutY(), 1e-100);
+        assertEquals(300, child.getWidth(), 1e-100);
+        assertEquals(400, child.getHeight(), 1e-100);
+
+        anchorpane.resize(500,500);
+        anchorpane.layout();
+        assertEquals(190, child.getLayoutX(), 1e-100);
+        assertEquals(0, child.getLayoutY(), 1e-100);
+        assertEquals(300, child.getWidth(), 1e-100);
+        assertEquals(400, child.getHeight(), 1e-100);
+    }
 }