From 83ed101d56e2d494522f83a55e173f04c84f87af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 18 Apr 2012 12:10:45 +0300 Subject: [PATCH] Reserve space using margin instead of padding to reduce overflows --- .../gwt/client/ui/gridlayout/VGridLayout.java | 24 ++++++++-------- .../gwt/client/ui/layout/VLayoutSlot.java | 28 ++++++++++--------- .../VMeasuringOrderedLayout.java | 8 +++--- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java index 151705b1af..7629e09cac 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java @@ -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); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java b/src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java index f44d662e97..034fe35649 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java @@ -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); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java index 41c48883ec..de55ca98e6 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java @@ -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; } -- 2.39.5