# HG changeset patch # Parent 72ad480e56e5f1f2f73636a0d0f4b3161ee06acd RT-16051: TilePane and FlowPane return incorrect minimum sizes diff --git a/javafx-ui-common/src/javafx/scene/layout/FlowPane.java b/javafx-ui-common/src/javafx/scene/layout/FlowPane.java --- a/javafx-ui-common/src/javafx/scene/layout/FlowPane.java +++ b/javafx-ui-common/src/javafx/scene/layout/FlowPane.java @@ -420,11 +420,31 @@ } @Override protected double computeMinWidth(double height) { - return prefWidth(height); + if (getContentBias() == HORIZONTAL) { + double maxPref = 0; + for (int i = 0; i < getChildren().size(); i++) { + Node child = getChildren().get(i); + if (child.isManaged()) { + maxPref = Math.max(maxPref, child.prefWidth(-1)); + } + } + return getInsets().getLeft() + snapSize(maxPref) + getInsets().getRight(); + } + return computePrefWidth(height); } @Override protected double computeMinHeight(double width) { - return prefHeight(width); + if (getContentBias() == VERTICAL) { + double maxPref = 0; + for (int i = 0; i < getChildren().size(); i++) { + Node child = getChildren().get(i); + if (child.isManaged()) { + maxPref = Math.max(maxPref, child.prefHeight(-1)); + } + } + return getInsets().getTop() + snapSize(maxPref) + getInsets().getBottom(); + } + return computePrefHeight(width); } @Override protected double computePrefWidth(double forHeight) { diff --git a/javafx-ui-common/src/javafx/scene/layout/TilePane.java b/javafx-ui-common/src/javafx/scene/layout/TilePane.java --- a/javafx-ui-common/src/javafx/scene/layout/TilePane.java +++ b/javafx-ui-common/src/javafx/scene/layout/TilePane.java @@ -589,11 +589,17 @@ } @Override protected double computeMinWidth(double height) { - return prefWidth(height); + if (getContentBias() == Orientation.HORIZONTAL) { + return getInsets().getLeft() + computeTileWidth(getManagedChildren()) + getInsets().getRight(); + } + return computePrefWidth(height); } @Override protected double computeMinHeight(double width) { - return prefHeight(width); + if (getContentBias() == Orientation.VERTICAL) { + return getInsets().getTop() + computeTileHeight(getManagedChildren()) + getInsets().getBottom(); + } + return computePrefHeight(width); } @Override protected double computePrefWidth(double forHeight) { diff --git a/javafx-ui-common/test/unit/javafx/scene/layout/FlowPaneTest.java b/javafx-ui-common/test/unit/javafx/scene/layout/FlowPaneTest.java --- a/javafx-ui-common/test/unit/javafx/scene/layout/FlowPaneTest.java +++ b/javafx-ui-common/test/unit/javafx/scene/layout/FlowPaneTest.java @@ -40,14 +40,14 @@ } @Test public void testSimpleFlowPane() { - for(int i = 0; i < 3; i++) { + for(int i = 0; i < 3; i++) { // 6 children MockResizable child1 = new MockResizable(100,200); Rectangle child2 = new Rectangle(100, 100); flowpane.getChildren().addAll(child1, child2); } - assertEquals(400, flowpane.minWidth(-1), 1e-100); - assertEquals(400, flowpane.minHeight(-1), 1e-100); + assertEquals(100, flowpane.minWidth(-1), 1e-100); + assertEquals(900, flowpane.minHeight(100), 1e-100); assertEquals(400, flowpane.prefWidth(-1), 1e-100); assertEquals(400, flowpane.prefHeight(-1), 1e-100); @@ -79,6 +79,30 @@ assertEquals(100, last.getLayoutBounds().getHeight(), 1e-100); } + @Test public void testEmptyHorizontalFlowPaneMinWidthIsZero() { + FlowPane flowpane = new FlowPane(); + + assertEquals(0, flowpane.minWidth(-1), 0); + } + + @Test public void testEmptyHorizontalFlowPaneMinHeightIsZero() { + FlowPane flowpane = new FlowPane(); + + assertEquals(0, flowpane.minHeight(-1), 0); + } + + @Test public void testEmptyVerticalFlowPaneMinWidthIsZero() { + FlowPane flowpane = new FlowPane(Orientation.VERTICAL); + + assertEquals(0, flowpane.minWidth(-1), 0); + } + + @Test public void testEmptyVerticalFlowPaneMinHeightIsZero() { + FlowPane flowpane = new FlowPane(Orientation.VERTICAL); + + assertEquals(0, flowpane.minHeight(-1), 0); + } + @Test public void testHorizontalFlowPaneAlignmentTopLeft() { for(int i = 0; i < 3; i++) { MockResizable child1 = new MockResizable(100,200); @@ -754,8 +778,8 @@ FlowPane.setMargin(first, new Insets(10,20,30,40)); - assertEquals(400, flowpane.minWidth(-1), 1e-100); - assertEquals(440, flowpane.minHeight(-1), 1e-100); + assertEquals(100, flowpane.minWidth(-1), 1e-100); + assertEquals(940, flowpane.minHeight(100), 1e-100); assertEquals(400, flowpane.prefWidth(-1), 1e-100); assertEquals(440, flowpane.prefHeight(-1), 1e-100); diff --git a/javafx-ui-common/test/unit/javafx/scene/layout/TilePaneTest.java b/javafx-ui-common/test/unit/javafx/scene/layout/TilePaneTest.java --- a/javafx-ui-common/test/unit/javafx/scene/layout/TilePaneTest.java +++ b/javafx-ui-common/test/unit/javafx/scene/layout/TilePaneTest.java @@ -78,14 +78,49 @@ assertEquals(Pos.CENTER, tilepane.getTileAlignment()); } - @Test public void testTilePaneMinSize() { - assertEquals(500, tilepane.minWidth(-1), 1e-100); - assertEquals(600, tilepane.minHeight(-1), 1e-100); + @Test public void testHorizontalTilePaneMinSize() { + assertEquals(200, htilepane.minWidth(-1), 1e-100); + assertEquals(2400, htilepane.minHeight(100), 1e-100); } - @Test public void testPrefSize() { - assertEquals(500, tilepane.prefWidth(-1), 1e-100); - assertEquals(600, tilepane.prefHeight(-1), 1e-100); + @Test public void testHorizontalTilePanePrefSize() { + assertEquals(1000, htilepane.prefWidth(-1), 1e-100); + assertEquals(600, htilepane.prefHeight(-1), 1e-100); + } + + @Test public void testVerticalTilePaneMinSize() { + assertEquals(300, vtilepane.minHeight(-1), 1e-100); + assertEquals(1600, vtilepane.minWidth(300), 1e-100); + } + + @Test public void testVerticalTilePanePrefSize() { + assertEquals(1500, vtilepane.prefHeight(-1), 1e-100); + assertEquals(400, vtilepane.prefWidth(-1), 1e-100); + } + + + @Test public void testEmptyHorizontalTilePaneMinWidthIsZero() { + TilePane Tilepane = new TilePane(); + + assertEquals(0, Tilepane.minWidth(-1), 0); + } + + @Test public void testEmptyHorizontalTilePaneMinHeightIsZero() { + TilePane Tilepane = new TilePane(); + + assertEquals(0, Tilepane.minHeight(-1), 0); + } + + @Test public void testEmptyVerticalTilePaneMinWidthIsZero() { + TilePane Tilepane = new TilePane(Orientation.VERTICAL); + + assertEquals(0, Tilepane.minWidth(-1), 0); + } + + @Test public void testEmptyVerticalTilePaneMinHeightIsZero() { + TilePane Tilepane = new TilePane(Orientation.VERTICAL); + + assertEquals(0, Tilepane.minHeight(-1), 0); } @Test public void testLayoutWithPrefSize() { @@ -664,7 +699,7 @@ TilePane.setMargin(first, new Insets(10,20,30,40)); - assertEquals(800, tilepane.minWidth(-1), 1e-100); + assertEquals(160, tilepane.minWidth(-1), 1e-100); assertEquals(720, tilepane.minHeight(-1), 1e-100); assertEquals(800, tilepane.prefWidth(-1), 1e-100); assertEquals(720, tilepane.prefHeight(-1), 1e-100); @@ -705,7 +740,7 @@ tilepane.getChildren().addAll(child1, child2); } - assertEquals(500, tilepane.minWidth(-1), 1e-100); + assertEquals(100, tilepane.minWidth(-1), 1e-100); assertEquals(600, tilepane.minHeight(-1), 1e-100); assertEquals(500, tilepane.prefWidth(-1), 1e-100); assertEquals(600, tilepane.prefHeight(-1), 1e-100);