From 1309bd8ff04c91498bb64c8cdf5353141922c8bc Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 13 Feb 2009 21:20:26 +0000 Subject: [PATCH] Test case and fix for #2591 - A Label leaves empty space in a VerticalLayout in some cases svn changeset:6839/svn branch:trunk --- .../gwt/client/ui/IOrderedLayout.java | 67 +++++++++---------- ...ticalLayoutWithRelativeSizeComponents.java | 38 +++++++++++ 2 files changed, 71 insertions(+), 34 deletions(-) create mode 100644 src/com/itmill/toolkit/tests/layouts/VerticalLayoutWithRelativeSizeComponents.java diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java index fae87ccd88..ffa30f724b 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java @@ -194,26 +194,24 @@ public class IOrderedLayout extends CellBasedLayout { */ if ((isHorizontal() && isDynamicHeight()) || (isVertical() && isDynamicWidth())) { - Size oldSize = new Size(activeLayoutSize.getWidth(), - activeLayoutSize.getHeight()); - calculateLayoutDimensions(); - - /* - * If layout dimension is changed due to relative sized components - * we must also update container sizes - */ - if (!oldSize.equals(activeLayoutSize)) { - calculateContainerSize(); - } - + layoutSizeMightHaveChanged(); } // w.mark("Layout dimensions updated"); /* Update component spacing */ updateContainerMargins(); - /* Recalculate component sizes and alignments */ - recalculateComponentSizesAndAlignments(); + /* + * Update component sizes for components with relative size in non-main + * direction + */ + if (updateRelativeSizesInNonMainDirection()) { + // Sizes updated - might affect the other dimension so we need to + // recheck the widget sizes and recalculate layout dimensions + updateWidgetSizes(); + layoutSizeMightHaveChanged(); + } + calculateAlignments(); // w.mark("recalculateComponentSizesAndAlignments done"); setRootSize(); @@ -232,6 +230,19 @@ public class IOrderedLayout extends CellBasedLayout { sizeHasChangedDuringRendering = false; } + private void layoutSizeMightHaveChanged() { + Size oldSize = new Size(activeLayoutSize.getWidth(), activeLayoutSize + .getHeight()); + calculateLayoutDimensions(); + + /* + * If layout dimension changes we must also update container sizes + */ + if (!oldSize.equals(activeLayoutSize)) { + calculateContainerSize(); + } + } + private void updateWidgetSizes() { for (ChildComponentContainer childComponentContainer : widgetToComponentContainer .values()) { @@ -298,44 +309,31 @@ public class IOrderedLayout extends CellBasedLayout { } - private void recalculateComponentSizesAndAlignments() { - if (widgetToComponentContainer.isEmpty()) { - return; - } - - /* - * Update the height of relative height components in a horizontal - * layout or the width for relative width components in a vertical - * layout - */ - updateRelativeSizesInNonMainDirection(); - - /* Calculate alignments */ - calculateAlignments(); - - } - /** * Updated components with relative height in horizontal layouts and * components with relative width in vertical layouts. This is only needed * if the height (horizontal layout) or width (vertical layout) has not been * specified. */ - private void updateRelativeSizesInNonMainDirection() { + private boolean updateRelativeSizesInNonMainDirection() { int updateDirection = 1 - orientation; if ((updateDirection == ORIENTATION_HORIZONTAL && !isDynamicWidth()) || (updateDirection == ORIENTATION_VERTICAL && !isDynamicHeight())) { - return; + return false; } + boolean updated = false; for (ChildComponentContainer componentContainer : widgetToComponentContainer .values()) { if (componentContainer.isComponentRelativeSized(updateDirection)) { client.handleComponentRelativeSize(componentContainer .getWidget()); } + + updated = true; } + return updated; } private int calculateLayoutDimensions() { @@ -724,7 +722,8 @@ public class IOrderedLayout extends CellBasedLayout { recalculateLayout(); } - recalculateComponentSizesAndAlignments(); + updateRelativeSizesInNonMainDirection(); + calculateAlignments(); setRootSize(); } diff --git a/src/com/itmill/toolkit/tests/layouts/VerticalLayoutWithRelativeSizeComponents.java b/src/com/itmill/toolkit/tests/layouts/VerticalLayoutWithRelativeSizeComponents.java new file mode 100644 index 0000000000..37e7897097 --- /dev/null +++ b/src/com/itmill/toolkit/tests/layouts/VerticalLayoutWithRelativeSizeComponents.java @@ -0,0 +1,38 @@ +package com.itmill.toolkit.tests.layouts; + +import com.itmill.toolkit.tests.components.TestBase; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.Label; + +public class VerticalLayoutWithRelativeSizeComponents extends TestBase { + + @Override + protected String getDescription() { + return "A undefined wide VerticalLayout containing a 100% wide label, a Button and another identical label. The labels should be as wide as the button (400px) and there should be no extra space between the bottom of the first label and the button."; + } + + @Override + protected Integer getTicketNumber() { + return 2591; + } + + @Override + protected void setup() { + getLayout().setSizeUndefined(); + getMainWindow().getLayout().setHeight(null); + + Label l = new Label( + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc condimentum urna quis leo. In hac habitasse platea dictumst. Pellentesque tincidunt. Sed libero nisl, faucibus in, laoreet pellentesque, consectetur non, dolor. Sed tortor. Ut pretium sapien. Cras elementum enim non lacus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla velit est, aliquam a, pellentesque a, iaculis nec, sapien. Ut ultrices ligula vitae nulla. Morbi sem pede, iaculis ac, condimentum a, ornare eget, nisi. Aliquam hendrerit pulvinar massa. Vestibulum pretium purus eu augue. Sed posuere elit ut magna. Cras consequat faucibus nunc. Vestibulum quis diam."); + Label l2 = new Label( + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc condimentum urna quis leo. In hac habitasse platea dictumst. Pellentesque tincidunt. Sed libero nisl, faucibus in, laoreet pellentesque, consectetur non, dolor. Sed tortor. Ut pretium sapien. Cras elementum enim non lacus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla velit est, aliquam a, pellentesque a, iaculis nec, sapien. Ut ultrices ligula vitae nulla. Morbi sem pede, iaculis ac, condimentum a, ornare eget, nisi. Aliquam hendrerit pulvinar massa. Vestibulum pretium purus eu augue. Sed posuere elit ut magna. Cras consequat faucibus nunc. Vestibulum quis diam."); + l.setWidth("100%"); + l2.setWidth("100%"); + + Button b = new Button("This defines the width"); + b.setWidth("400px"); + addComponent(l); + addComponent(b); + addComponent(l2); + } + +} -- 2.39.5