Skip to content

Commit

Permalink
VerticalLayout has spacing = true and margin = true by default .
Browse files Browse the repository at this point in the history
HorizontalLayout has spacing = true and margin = false by default.

Fixes vaadin/framework8-issues#526
  • Loading branch information
Ilia Motornyi committed Dec 12, 2016
1 parent e63b51a commit 95a6163
Show file tree
Hide file tree
Showing 64 changed files with 190 additions and 137 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/com/vaadin/ui/AbstractLayout.java
Expand Up @@ -105,7 +105,7 @@ protected MarginInfo readMargin(Element design, MarginInfo defMargin,
*/ */
protected void writeMargin(Element design, MarginInfo margin, protected void writeMargin(Element design, MarginInfo margin,
MarginInfo defMargin, DesignContext context) { MarginInfo defMargin, DesignContext context) {
if (margin.hasAll()) { if (margin.hasAll() || margin.hasNone()) {
DesignAttributeHandler.writeAttribute("margin", design.attributes(), DesignAttributeHandler.writeAttribute("margin", design.attributes(),
margin.hasAll(), defMargin.hasAll(), boolean.class, margin.hasAll(), defMargin.hasAll(), boolean.class,
context); context);
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/com/vaadin/ui/HorizontalLayout.java
Expand Up @@ -33,7 +33,7 @@ public class HorizontalLayout extends AbstractOrderedLayout {
* Constructs an empty HorizontalLayout. * Constructs an empty HorizontalLayout.
*/ */
public HorizontalLayout() { public HorizontalLayout() {

setSpacing(true);
} }


/** /**
Expand Down
5 changes: 2 additions & 3 deletions server/src/main/java/com/vaadin/ui/LegacyWindow.java
Expand Up @@ -40,7 +40,7 @@ public class LegacyWindow extends UI {
*/ */
public LegacyWindow() { public LegacyWindow() {
super(new VerticalLayout()); super(new VerticalLayout());
((VerticalLayout) getContent()).setMargin(true); ((VerticalLayout) getContent()).setSpacing(false);
} }


/** /**
Expand All @@ -50,8 +50,7 @@ public LegacyWindow() {
* the caption of the window * the caption of the window
*/ */
public LegacyWindow(String caption) { public LegacyWindow(String caption) {
super(new VerticalLayout()); this();
((VerticalLayout) getContent()).setMargin(true);
setCaption(caption); setCaption(caption);
} }


Expand Down
2 changes: 2 additions & 0 deletions server/src/main/java/com/vaadin/ui/VerticalLayout.java
Expand Up @@ -35,6 +35,8 @@ public class VerticalLayout extends AbstractOrderedLayout {
*/ */
public VerticalLayout() { public VerticalLayout() {
setWidth("100%"); setWidth("100%");
setSpacing(true);
setMargin(true);
} }


/** /**
Expand Down
Expand Up @@ -25,7 +25,7 @@
public abstract class DeclarativeMarginTestBase<L extends Layout & MarginHandler> public abstract class DeclarativeMarginTestBase<L extends Layout & MarginHandler>
extends DeclarativeTestBase<L> { extends DeclarativeTestBase<L> {


protected void testMargins(String componentTag) { protected void testMargins(String componentTag, boolean defaultMargin) {


for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
boolean top = (i & 1) == 1; boolean top = (i & 1) == 1;
Expand All @@ -35,37 +35,41 @@ protected void testMargins(String componentTag) {


MarginInfo m = new MarginInfo(top, right, bottom, left); MarginInfo m = new MarginInfo(top, right, bottom, left);


String design = getMarginTag(componentTag, top, right, bottom, String design = getMarginTag(componentTag, defaultMargin, top, right, bottom,
left); left);


// The assertEquals machinery in DeclarativeTestBase uses bean // The assertEquals machinery in DeclarativeTestBase uses bean
// introspection and MarginInfo is not a proper bean. It ends up // introspection and MarginInfo is not a proper bean. It ends up
// considering *all* MarginInfo objects equal... (#18229) // considering *all* MarginInfo objects equal... (#18229)
L layout = read(design); L layout = read(design);
Assert.assertEquals(m, layout.getMargin()); Assert.assertEquals("For tag: " + design, m, layout.getMargin());


testWrite(design, layout); testWrite(design, layout);
} }
} }


private String getMarginTag(String componentTag, boolean top, boolean right, private String getMarginTag(String componentTag, boolean defaultMargin, boolean top, boolean right,
boolean bottom, boolean left) { boolean bottom, boolean left) {
String s = "<" + componentTag + " "; String s = "<" + componentTag + " ";
String suffix = defaultMargin ? "=false " : " ";


if (left && right && top && bottom) { if (top == left && top == right && top == bottom) {
s += "margin"; if(top != defaultMargin)
{
s += "margin" + suffix;
}
} else { } else {
if (left) { if (left != defaultMargin) {
s += "margin-left "; s += "margin-left" + suffix;
} }
if (right) { if (right != defaultMargin) {
s += "margin-right "; s += "margin-right" + suffix;
} }
if (top) { if (top != defaultMargin) {
s += "margin-top "; s += "margin-top" + suffix;
} }
if (bottom) { if (bottom != defaultMargin) {
s += "margin-bottom "; s += "margin-bottom" + suffix;
} }
} }
return s + " />"; return s + " />";
Expand Down
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;


import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;


import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.shared.ui.label.ContentMode;
Expand All @@ -40,8 +41,13 @@ public class AbstractOrderedLayoutDeclarativeTest
private List<String> defaultAlignments = Arrays.asList(":top", ":left"); private List<String> defaultAlignments = Arrays.asList(":top", ":left");


@Test @Test
public void testMargins() { public void testMarginsVertical() {
testMargins("vaadin-vertical-layout"); testMargins("vaadin-vertical-layout", true);
}

@Test
public void testMarginsHorizontal() {
testMargins("vaadin-horizontal-layout", false);
} }


@Test @Test
Expand Down
Expand Up @@ -38,7 +38,7 @@ public class GridLayoutDeclarativeTest


@Test @Test
public void testMargins() { public void testMargins() {
testMargins("vaadin-grid-layout"); testMargins("vaadin-grid-layout",false);
} }


@Test @Test
Expand Down
11 changes: 11 additions & 0 deletions shared/src/main/java/com/vaadin/shared/ui/MarginInfo.java
Expand Up @@ -148,6 +148,17 @@ public boolean hasAll() {
return (bitMask & ALL) == ALL; return (bitMask & ALL) == ALL;
} }


/**
* Checks if this MarginInfo object has no margins enabled.
*
* @since 8.0.0
*
* @return true if all edges have margins disabled
*/
public boolean hasNone() {
return (bitMask & ALL) == 0;
}

/** /**
* Checks if this MarginInfo object has the left edge margin enabled. * Checks if this MarginInfo object has the left edge margin enabled.
* *
Expand Down
Expand Up @@ -29,10 +29,12 @@ public void init(VaadinRequest request) {
label.setWidth("100%"); label.setWidth("100%");


VerticalLayout rootLayout = new VerticalLayout(); VerticalLayout rootLayout = new VerticalLayout();
rootLayout.setMargin(true); rootLayout.setSpacing(false);
setContent(rootLayout); setContent(rootLayout);


layout = new VerticalLayout(); layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);


rootLayout.addComponent(label); rootLayout.addComponent(label);
rootLayout.addComponent(layout); rootLayout.addComponent(layout);
Expand Down
Expand Up @@ -39,6 +39,8 @@ && getBrowser().getBrowserMajorVersion() == 9) {
window.addComponent(label); window.addComponent(label);


layout = new VerticalLayout(); layout = new VerticalLayout();
layout.setMargin(false);
layout.setSpacing(false);
window.addComponent(layout); window.addComponent(layout);
((VerticalLayout) window.getContent()).setExpandRatio(layout, 1); ((VerticalLayout) window.getContent()).setExpandRatio(layout, 1);


Expand Down
Expand Up @@ -17,6 +17,7 @@ public class BrowserFrameIsVisible extends TestBase {
protected void setup() { protected void setup() {


HorizontalLayout buttonLayout = new HorizontalLayout(); HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setSpacing(false);
addComponent(buttonLayout); addComponent(buttonLayout);


Button page1 = new Button("Hello World"); Button page1 = new Button("Hello World");
Expand Down
Expand Up @@ -32,6 +32,8 @@ public class CustomFieldSize extends AbstractReindeerTestUI {
@Override @Override
protected void setup(VaadinRequest request) { protected void setup(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout(); VerticalLayout layout = new VerticalLayout();
layout.setMargin(false);
layout.setSpacing(false);
setContent(layout); setContent(layout);
layout.setWidth("50px"); layout.setWidth("50px");


Expand Down
Expand Up @@ -29,7 +29,7 @@ protected void setup() {
private Component makeOtherComponentWrapper(DragStartMode componentOther) { private Component makeOtherComponentWrapper(DragStartMode componentOther) {
VerticalLayout parent = new VerticalLayout(); VerticalLayout parent = new VerticalLayout();
parent.setWidth("200px"); parent.setWidth("200px");
parent.setSpacing(true); parent.setMargin(false);


CssLayout header = new CssLayout(); CssLayout header = new CssLayout();
Label dragStartModeLabel = new Label( Label dragStartModeLabel = new Label(
Expand Down
Expand Up @@ -15,6 +15,8 @@ public class InitiallyDisabledGrid extends UI {
@Override @Override
protected void init(VaadinRequest request) { protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout(); VerticalLayout layout = new VerticalLayout();
layout.setMargin(false);
layout.setSpacing(false);
setContent(layout); setContent(layout);
layout.setSizeFull(); layout.setSizeFull();
layout.setWidth("600px"); layout.setWidth("600px");
Expand All @@ -25,6 +27,8 @@ protected void init(VaadinRequest request) {


layout.addComponent(button); layout.addComponent(button);
VerticalLayout l = new VerticalLayout(); VerticalLayout l = new VerticalLayout();
l.setMargin(false);
l.setSpacing(false);
l.setSizeFull(); l.setSizeFull();
l.addComponent(grid); l.addComponent(grid);


Expand Down
Expand Up @@ -68,6 +68,8 @@ protected void setup(VaadinRequest request) {


private VerticalLayout createVerticalLayout(boolean useCaption) { private VerticalLayout createVerticalLayout(boolean useCaption) {
VerticalLayout vl = new VerticalLayout(); VerticalLayout vl = new VerticalLayout();
vl.setMargin(false);
vl.setSpacing(false);
vl.setWidth("320px"); vl.setWidth("320px");


addLabel(vl, "200px", Alignment.MIDDLE_LEFT, useCaption); addLabel(vl, "200px", Alignment.MIDDLE_LEFT, useCaption);
Expand Down
Expand Up @@ -2,9 +2,9 @@


import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI; import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Button; import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.GridLayout; import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label; import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
Expand All @@ -13,7 +13,7 @@ public class MoveComponentsFromGridLayoutToInnerLayout extends AbstractReindeerT


protected Button testButton; protected Button testButton;
private GridLayout gl; private GridLayout gl;
protected ComponentContainer vl; protected AbstractOrderedLayout vl;


@Override @Override
protected void setup(VaadinRequest request) { protected void setup(VaadinRequest request) {
Expand All @@ -34,6 +34,8 @@ public void buttonClick(ClickEvent event) {
gl.addComponent(testButton); gl.addComponent(testButton);


vl = new VerticalLayout(); vl = new VerticalLayout();
vl.setMargin(false);
vl.setSpacing(false);
vl.addComponent(new Label("I'm inside the inner layout")); vl.addComponent(new Label("I'm inside the inner layout"));
gl.addComponent(vl); gl.addComponent(vl);


Expand Down
Expand Up @@ -34,7 +34,7 @@ protected void setup(VaadinRequest request) {
VerticalLayout container = new VerticalLayout(); VerticalLayout container = new VerticalLayout();
container.setStyleName("mystyle"); container.setStyleName("mystyle");
container.setId("container"); container.setId("container");
container.setSpacing(true); container.setMargin(false);
container.setSizeFull(); container.setSizeFull();
addComponent(container); addComponent(container);


Expand Down
Expand Up @@ -29,7 +29,7 @@ public class UndefinedSizeScrollbars extends AbstractReindeerTestUI {
@Override @Override
protected void setup(VaadinRequest request) { protected void setup(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout(); VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true); layout.setMargin(false);
layout.setSizeFull(); layout.setSizeFull();
setContent(layout); setContent(layout);


Expand Down
Expand Up @@ -27,7 +27,7 @@ public class SliderResize extends AbstractReindeerTestUI {
@Override @Override
protected void setup(VaadinRequest request) { protected void setup(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout(); final VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true); layout.setMargin(false);
layout.setWidth("500px"); layout.setWidth("500px");
addComponent(layout); addComponent(layout);


Expand Down

0 comments on commit 95a6163

Please sign in to comment.