Browse Source

Don't include relative sizes in expand compensation (#10222)

Change-Id: I1b94a8ffbbe66e64a585e1d7729dae3af6d815b6
tags/7.0.0.rc1
Leif Åstrand 11 years ago
parent
commit
c322474415

+ 8
- 0
client/src/com/vaadin/client/ui/orderedlayout/Slot.java View File

@@ -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();
}
}
}

+ 16
- 1
client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java View File

@@ -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

+ 72
- 0
uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.html View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/run/com.vaadin.tests.components.orderedlayout.RelativeChildrenWithoutExpand?restartApplication</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
<td></td>
</tr>

</tbody></table>
</body>
</html>

+ 55
- 0
uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.java View File

@@ -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);
}
}

Loading…
Cancel
Save