]> source.dussan.org Git - vaadin-framework.git/commitdiff
Properly reserve room for captions to the right (#8313)
authorLeif Åstrand <leif@vaadin.com>
Thu, 23 Feb 2012 07:18:43 +0000 (09:18 +0200)
committerLeif Åstrand <leif@vaadin.com>
Thu, 23 Feb 2012 07:18:43 +0000 (09:18 +0200)
src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java

index f5ec7826c3d0585086fda56e7017ab306086406d..17ccf7b84c7e1a14f63be35f15af86a0cff266d8 100644 (file)
@@ -60,17 +60,12 @@ public abstract class VLayoutSlot {
             double allocatedSpace) {
         Style style = wrapper.getStyle();
 
-        if (isRelativeWidth()) {
-            style.setPropertyPx("width", (int) allocatedSpace);
-            style.clearProperty("minWidth");
-        } else {
-            style.clearProperty("width");
-            style.setPropertyPx("minWidth", getCaptionWidth());
-        }
+        double availableWidth = allocatedSpace;
 
         VCaption caption = getCaption();
         Style captionStyle = caption != null ? caption.getElement().getStyle()
                 : null;
+        int captionWidth = getCaptionWidth();
 
         boolean captionAboveCompnent;
         if (caption == null) {
@@ -79,12 +74,29 @@ public abstract class VLayoutSlot {
         } else {
             captionAboveCompnent = !caption.shouldBePlacedAfterComponent();
             if (!captionAboveCompnent) {
-                style.setPaddingRight(getCaptionWidth(), Unit.PX);
-                captionStyle.setLeft(getWidgetWidth(), Unit.PX);
+                style.setPaddingRight(captionWidth, Unit.PX);
+                availableWidth -= captionWidth;
+                captionStyle.clearLeft();
+                captionStyle.setRight(0, Unit.PX);
             } else {
                 style.clearPaddingRight();
                 captionStyle.setLeft(0, Unit.PX);
+                captionStyle.clearRight();
+            }
+        }
+
+        if (isRelativeWidth()) {
+            style.setPropertyPx("width", (int) availableWidth);
+            style.clearProperty("minWidth");
+            style.clearProperty("maxWidth");
+        } else {
+            style.clearProperty("width");
+            if (caption != null && captionAboveCompnent) {
+                style.setPropertyPx("minWidth", captionWidth);
+            } else {
+                style.clearProperty("minWidth");
             }
+            style.setPropertyPx("maxWidth", (int) availableWidth);
         }
 
         AlignmentInfo alignment = getAlignment();
@@ -93,8 +105,7 @@ public abstract class VLayoutSlot {
             if (alignment.isHorizontalCenter()) {
                 currentLocation += (allocatedSpace - usedWidth) / 2d;
                 if (captionAboveCompnent) {
-                    double captionWidth = getCaptionWidth();
-                    captionStyle.setLeft(usedWidth / 2 - (captionWidth / 2),
+                    captionStyle.setLeft(usedWidth / 2 - (captionWidth / 2d),
                             Unit.PX);
                     captionStyle.clearRight();
                 }