From 02d9fe8fd10cbcfd775395cd655495802cb536ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 28 Feb 2012 15:03:49 +0200 Subject: [PATCH] Improve positioning of captions (#8313) --- .../gwt/client/ui/layout/VLayoutSlot.java | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) 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 1ee7049510..4494ef95d0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/VLayoutSlot.java @@ -90,53 +90,58 @@ public abstract class VLayoutSlot { if (isRelativeWidth()) { style.setPropertyPx("width", (int) availableWidth); - style.clearProperty("minWidth"); } else { style.clearProperty("width"); - if (caption != null && captionAboveCompnent) { - style.setPropertyPx("minWidth", captionWidth); - } else { - style.clearProperty("minWidth"); - } } AlignmentInfo alignment = getAlignment(); if (!alignment.isLeft()) { - double usedWidth = getWidgetWidth(); + double usedWidth; + if (isRelativeWidth()) { + String percentWidth = getWidget().getElement().getStyle() + .getWidth(); + double percentage = parsePercent(percentWidth); + usedWidth = availableWidth * (percentage / 100); + } else { + usedWidth = getWidgetWidth(); + } if (alignment.isHorizontalCenter()) { currentLocation += (allocatedSpace - usedWidth) / 2d; if (captionAboveCompnent) { - captionStyle.setLeft(usedWidth / 2 - (captionWidth / 2d), + captionStyle.setLeft((usedWidth - captionWidth) / 2, Unit.PX); - captionStyle.clearRight(); } } else { currentLocation += (allocatedSpace - usedWidth); if (captionAboveCompnent) { - captionStyle.clearLeft(); - captionStyle.setRight(0, Unit.PX); + captionStyle.setLeft(usedWidth - captionWidth, Unit.PX); } } } else { if (captionAboveCompnent) { captionStyle.setLeft(0, Unit.PX); - captionStyle.clearRight(); } } style.setLeft(currentLocation, Unit.PX); } + private double parsePercent(String size) { + return Double.parseDouble(size.replaceAll("%", "")); + } + public void positionVertically(double currentLocation, double allocatedSpace) { Style style = wrapper.getStyle(); double contentHeight = allocatedSpace; + int captionHeight; VCaption caption = getCaption(); if (caption == null || caption.shouldBePlacedAfterComponent()) { style.clearPaddingTop(); + captionHeight = 0; } else { - int captionHeight = getCaptionHeight(); + captionHeight = getCaptionHeight(); contentHeight -= captionHeight; style.setPaddingTop(captionHeight, Unit.PX); } @@ -149,7 +154,14 @@ public abstract class VLayoutSlot { AlignmentInfo alignment = getAlignment(); if (!alignment.isTop()) { - int usedHeight = getUsedHeight(); + double usedHeight; + if (isRelativeHeight()) { + String height = getWidget().getElement().getStyle().getHeight(); + double percentage = parsePercent(height); + usedHeight = captionHeight + contentHeight * (percentage / 100); + } else { + usedHeight = getUsedHeight(); + } if (alignment.isVerticalCenter()) { currentLocation += (allocatedSpace - usedHeight) / 2d; } else { -- 2.39.5