From 77aed50851264cf89025fcf0a082e83027d90f68 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Tue, 5 Feb 2013 11:59:42 +0200 Subject: Fixed middle vertical alignments in HorizontalLayout #10852 Change-Id: I85dac7b89ec4ec670cf92e5c760090fbef5929af --- .../AbstractOrderedLayoutConnector.java | 17 ++++++++- .../HorizontalLayoutVerticalAlign.html | 27 +++++++++++++ .../HorizontalLayoutVerticalAlign.java | 44 ++++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.html create mode 100644 uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.java diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index afe81c79a0..77def89e9e 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -196,6 +196,12 @@ public abstract class AbstractOrderedLayoutConnector extends */ private boolean hasChildrenWithRelativeHeight = false; + /** + * Keep track of whether any child is middle aligned. Used to determine if + * measurements are needed to make middle aligned children work. + */ + private boolean hasChildrenWithMiddleAlignment = false; + /** * Keeps track of whether slots should be expanded based on available space. */ @@ -340,6 +346,7 @@ public abstract class AbstractOrderedLayoutConnector extends processedResponseId = lastResponseId; hasChildrenWithRelativeHeight = false; + hasChildrenWithMiddleAlignment = false; needsExpand = getWidget().vertical ? !isUndefinedHeight() : !isUndefinedWidth(); @@ -380,6 +387,10 @@ public abstract class AbstractOrderedLayoutConnector extends getState().childData.get(child).alignmentBitmask); slot.setAlignment(alignment); + if (alignment.isVerticalCenter()) { + hasChildrenWithMiddleAlignment = true; + } + double expandRatio = onlyZeroExpands ? 1 : getState().childData .get(child).expandRatio; @@ -429,8 +440,10 @@ public abstract class AbstractOrderedLayoutConnector extends return false; } - else if (!hasChildrenWithRelativeHeight) { - // Already works if there are no relative heights + else if (!hasChildrenWithRelativeHeight + && !hasChildrenWithMiddleAlignment) { + // Already works if there are no relative heights or middle aligned + // children return false; } diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.html b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.html new file mode 100644 index 0000000000..d16e4a3354 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.html @@ -0,0 +1,27 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.orderedlayout.HorizontalLayoutVerticalAlign?restartApplication
screenCapturealignments
+ + diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.java b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.java new file mode 100644 index 0000000000..4dc9d8129e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalLayoutVerticalAlign.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.orderedlayout; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextArea; + +public class HorizontalLayoutVerticalAlign extends TestBase { + + @Override + protected void setup() { + HorizontalLayout p = new HorizontalLayout(); + + p.addComponent(new TextArea()); + + Label top = new Label("top"); + p.addComponent(top); + p.setComponentAlignment(top, Alignment.TOP_CENTER); + + Label middle = new Label("middle"); + p.addComponent(middle); + p.setComponentAlignment(middle, Alignment.MIDDLE_CENTER); + + Label bottom = new Label("bottom"); + p.addComponent(bottom); + p.setComponentAlignment(bottom, Alignment.BOTTOM_CENTER); + + p.addComponent(new TextArea()); + + addComponent(p); + } + + @Override + protected String getDescription() { + return "Vertical alignments should be top-middle-bottom"; + } + + @Override + protected Integer getTicketNumber() { + return 10852; + } + +} -- cgit v1.2.3