]> source.dussan.org Git - vaadin-framework.git/commitdiff
Reserve space using margin instead of padding to reduce overflows
authorLeif Åstrand <leif@vaadin.com>
Wed, 18 Apr 2012 09:10:45 +0000 (12:10 +0300)
committerLeif Åstrand <leif@vaadin.com>
Wed, 18 Apr 2012 09:10:45 +0000 (12:10 +0300)
src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java
src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java
src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java

index 151705b1afb9f70ec90ed5e448aabecb066c99a9..7629e09cac5a49e2ef07764ffac69ee5b1ba5001 100644 (file)
@@ -201,15 +201,15 @@ public class VGridLayout extends ComplexPanel {
             for (int j = 0; j < cells[i].length; j++) {
                 Cell cell = cells[i][j];
                 if (cell != null) {
-                    int effectivePadding;
+                    int reservedMargin;
                     if (cell.rowspan + j >= cells[i].length) {
                         // Make room for layout padding for cells reaching the
                         // bottom of the layout
-                        effectivePadding = paddingBottom;
+                        reservedMargin = paddingBottom;
                     } else {
-                        effectivePadding = 0;
+                        reservedMargin = 0;
                     }
-                    cell.layoutVertically(y, effectivePadding);
+                    cell.layoutVertically(y, reservedMargin);
                 }
                 y += rowHeights[j] + verticalSpacing;
             }
@@ -235,15 +235,15 @@ public class VGridLayout extends ComplexPanel {
             for (int j = 0; j < cells[i].length; j++) {
                 Cell cell = cells[i][j];
                 if (cell != null) {
-                    int effectivePadding;
+                    int reservedMargin;
                     // Make room for layout padding for cells reaching the
                     // right edge of the layout
                     if (i + cell.colspan >= cells.length) {
-                        effectivePadding = paddingRight;
+                        reservedMargin = paddingRight;
                     } else {
-                        effectivePadding = 0;
+                        reservedMargin = 0;
                     }
-                    cell.layoutHorizontally(x, effectivePadding);
+                    cell.layoutHorizontally(x, reservedMargin);
                 }
             }
             x += columnWidths[i] + horizontalSpacing;
@@ -507,15 +507,15 @@ public class VGridLayout extends ComplexPanel {
             return height;
         }
 
-        public void layoutHorizontally(int x, int paddingRight) {
+        public void layoutHorizontally(int x, int marginRight) {
             if (slot != null) {
-                slot.positionHorizontally(x, getAvailableWidth(), paddingRight);
+                slot.positionHorizontally(x, getAvailableWidth(), marginRight);
             }
         }
 
-        public void layoutVertically(int y, int paddingBottom) {
+        public void layoutVertically(int y, int marginBottom) {
             if (slot != null) {
-                slot.positionVertically(y, getAvailableHeight(), paddingBottom);
+                slot.positionVertically(y, getAvailableHeight(), marginBottom);
             }
         }
 
index f44d662e973efbdea7a34b53ed2900f118430aad..034fe3564993979b998c4f3814d8234fc16bcb93 100644 (file)
@@ -60,7 +60,7 @@ public abstract class VLayoutSlot {
     }
 
     public void positionHorizontally(double currentLocation,
-            double allocatedSpace, double paddingRight) {
+            double allocatedSpace, double marginRight) {
         Style style = wrapper.getStyle();
 
         double availableWidth = allocatedSpace;
@@ -73,23 +73,25 @@ public abstract class VLayoutSlot {
         boolean captionAboveCompnent;
         if (caption == null) {
             captionAboveCompnent = false;
+            style.clearPaddingRight();
         } else {
             captionAboveCompnent = !caption.shouldBePlacedAfterComponent();
             if (!captionAboveCompnent) {
                 availableWidth -= captionWidth;
                 captionStyle.clearLeft();
-                captionStyle.setRight(paddingRight, Unit.PX);
-                paddingRight += captionWidth;
+                captionStyle.setRight(0, Unit.PX);
+                style.setPaddingRight(captionWidth, Unit.PX);
             } else {
                 captionStyle.setLeft(0, Unit.PX);
                 captionStyle.clearRight();
+                style.clearPaddingRight();
             }
         }
 
-        if (paddingRight > 0) {
-            style.setPaddingRight(paddingRight, Unit.PX);
+        if (marginRight > 0) {
+            style.setMarginRight(marginRight, Unit.PX);
         } else {
-            style.clearPaddingRight();
+            style.clearMarginRight();
         }
 
         if (isRelativeWidth()) {
@@ -142,7 +144,7 @@ public abstract class VLayoutSlot {
     }
 
     public void positionVertically(double currentLocation,
-            double allocatedSpace, double paddingBottom) {
+            double allocatedSpace, double marginBottom) {
         Style style = wrapper.getStyle();
 
         double contentHeight = allocatedSpace;
@@ -161,10 +163,10 @@ public abstract class VLayoutSlot {
             style.setPaddingTop(captionHeight, Unit.PX);
         }
 
-        if (paddingBottom > 0) {
-            style.setPaddingBottom(paddingBottom, Unit.PX);
+        if (marginBottom > 0) {
+            style.setMarginBottom(marginBottom, Unit.PX);
         } else {
-            style.clearPaddingBottom();
+            style.clearMarginBottom();
         }
 
         if (isRelativeHeight()) {
@@ -209,11 +211,11 @@ public abstract class VLayoutSlot {
     }
 
     public void positionInDirection(double currentLocation,
-            double allocatedSpace, double endingPadding, boolean isVertical) {
+            double allocatedSpace, double endingMargin, boolean isVertical) {
         if (isVertical) {
-            positionVertically(currentLocation, allocatedSpace, endingPadding);
+            positionVertically(currentLocation, allocatedSpace, endingMargin);
         } else {
-            positionHorizontally(currentLocation, allocatedSpace, endingPadding);
+            positionHorizontally(currentLocation, allocatedSpace, endingMargin);
         }
     }
 
index 41c48883ec9027d3664db300fbd17459e3fef8e0..de55ca98e65cc2a037e2ea29624547f7f311744c 100644 (file)
@@ -191,15 +191,15 @@ public class VMeasuringOrderedLayout extends ComplexPanel {
             double roundedSpace = Math.round(endLocation) - roundedLocation;
 
             // Reserve room for the padding if we're at the end
-            double slotEndPadding;
+            double slotEndMargin;
             if (i == children.size() - 1) {
-                slotEndPadding = endPadding;
+                slotEndMargin = endPadding;
             } else {
-                slotEndPadding = 0;
+                slotEndMargin = 0;
             }
 
             slot.positionInDirection(roundedLocation, roundedSpace,
-                    slotEndPadding, isVertical);
+                    slotEndMargin, isVertical);
 
             currentLocation = endLocation + spacingSize;
         }