From c5c10151a0b4e47883eff8f94563898b62d67f99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 14 Mar 2012 12:32:33 +0200 Subject: [PATCH] Fix a rounding problem with the positioning (#8313) --- .../client/ui/VMeasuringOrderedLayout.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java index 3c0e9af26d..a57c2dd902 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java @@ -151,14 +151,35 @@ public class VMeasuringOrderedLayout extends ComplexPanel { } double extraPixels = unallocatedSpace * childExpandRatio; - double allocatedSpace = extraPixels; + double endLocation = currentLocation + extraPixels; if (!slot.isRelativeInDirection(isVertical)) { - allocatedSpace += slot.getUsedSizeInDirection(isVertical); + endLocation += slot.getUsedSizeInDirection(isVertical); } - slot.positionInDirection(currentLocation, allocatedSpace, - isVertical); - currentLocation += allocatedSpace + spacingSize; + /* + * currentLocation and allocatedSpace are used with full precision + * to avoid missing pixels in the end. The pixel dimensions passed + * to the DOM are still rounded. Otherwise e.g. 10.5px start + * position + 10.5px space might be cause the component to go 1px + * beyond the edge as the effect of the browser's rounding may cause + * something similar to 11px + 11px. + * + * It's most efficient to use doubles all the way because native + * javascript emulates other number types using doubles. + */ + double roundedLocation = Math.round(currentLocation); + + /* + * Space is calculated as the difference between rounded start and + * end locations. Just rounding the space would cause e.g. 10.5px + + * 10.5px = 21px -> 11px + 11px = 22px but in this way we get 11px + + * 10px = 21px. + */ + double roundedSpace = Math.round(endLocation) - roundedLocation; + + slot.positionInDirection(roundedLocation, roundedSpace, isVertical); + + currentLocation = endLocation + spacingSize; } return allocatedSize; -- 2.39.5