From: Leif Åstrand Date: Fri, 4 Jan 2013 15:18:28 +0000 (+0200) Subject: Don't include relative sizes in expand compensation (#10222) X-Git-Tag: 7.0.0.rc1~82^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c322474415ed2fc546e763a2329fdd82a62b06ec;p=vaadin-framework.git Don't include relative sizes in expand compensation (#10222) Change-Id: I1b94a8ffbbe66e64a585e1d7729dae3af6d815b6 --- diff --git a/client/src/com/vaadin/client/ui/orderedlayout/Slot.java b/client/src/com/vaadin/client/ui/orderedlayout/Slot.java index 8b6ad14669..b59c3664c7 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/Slot.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/Slot.java @@ -661,4 +661,12 @@ public final class Slot extends SimplePanel { getElement().getParentElement().insertBefore(spacer, getElement()); } } + + public boolean isRelativeInDirection(boolean vertical) { + if (vertical) { + return hasRelativeHeight(); + } else { + return hasRelativeWidth(); + } + } } \ No newline at end of file diff --git a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java index a11251f0b0..84f946dec4 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java @@ -426,10 +426,25 @@ public class VAbstractOrderedLayout extends FlowPanel { } if (isExpanding) { + /* + * Expanded slots have relative sizes that together add up to 100%. + * To make room for slots without expand, we will add padding that + * is not considered for relative sizes and a corresponding negative + * margin for the unexpanded slots. We calculate the size by summing + * the size of all non-expanded non-relative slots. + * + * Relatively sized slots without expansion are considered to get + * 0px, but we still keep them visible (causing overflows) to help + * the developer see what's happening. Forcing them to only get 0px + * would make them disappear which would avoid overflows but would + * instead cause confusion as they would then just disappear without + * any obvious reason. + */ int totalSize = 0; for (Widget w : getChildren()) { Slot slot = (Slot) w; - if (slot.getExpandRatio() == 0) { + if (slot.getExpandRatio() == 0 + && !slot.isRelativeInDirection(vertical)) { if (layoutManager != null) { // TODO check caption position diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.html b/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.html new file mode 100644 index 0000000000..46252bc447 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.html @@ -0,0 +1,72 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.orderedlayout.RelativeChildrenWithoutExpand?restartApplication
clickvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertElementNotPresentvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]
clickvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertElementNotPresentvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]
clickvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertElementNotPresentvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]
clickvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertElementNotPresentvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]
clickvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertElementNotPresentvaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]
+ + diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.java b/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.java new file mode 100644 index 0000000000..a1ac1df307 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.java @@ -0,0 +1,55 @@ +package com.vaadin.tests.components.orderedlayout; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; + +public class RelativeChildrenWithoutExpand extends AbstractTestUI { + + private final String loremIpsum = "This is a label without expand but with relative width that shouldn't get any space at all. "; + + @Override + protected void setup(VaadinRequest request) { + final HorizontalLayout horizontalExpand = new HorizontalLayout(); + + VerticalLayout vl = new VerticalLayout(); + vl.addComponent(new Label(getTestDescription())); + vl.setSizeFull(); + + // Replacing default AbstractTestUI content to get the right expansions + setContent(vl); + + HorizontalLayout verticalExpand = new HorizontalLayout(); + verticalExpand.addComponent(new Button("Add relative child", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + horizontalExpand.addComponent(new Label(loremIpsum), 0); + } + })); + vl.addComponent(verticalExpand); + vl.setExpandRatio(verticalExpand, 1); + + horizontalExpand.setWidth("100%"); + vl.addComponent(horizontalExpand); + + Label lblExpandRatio1 = new Label( + "This is an expanding label that will get all of the normal space in the component."); + horizontalExpand.addComponent(lblExpandRatio1); + horizontalExpand.setExpandRatio(lblExpandRatio1, 1); + } + + @Override + protected String getTestDescription() { + return "HorizontalLayout containing relatively sized components that are not expanded should not cause infinite layout loops when scrollbars appear. Add children until the entire space is filled up."; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(10222); + } +} \ No newline at end of file