diff options
author | Mikael Grankvist <mgrankvi@vaadin.com> | 2015-03-12 14:19:14 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-04-10 12:12:24 +0000 |
commit | 37be37449713b3e07fc2e284695d94ea116e43e7 (patch) | |
tree | 8ea64d01c55dd1a6d6d5c5e15b5f95378b969545 /client | |
parent | d175f53e44bb835139fd10097fed4cb8eee58870 (diff) | |
download | vaadin-framework-37be37449713b3e07fc2e284695d94ea116e43e7.tar.gz vaadin-framework-37be37449713b3e07fc2e284695d94ea116e43e7.zip |
Grid layout slots should be slot size not slot content size (#17039)
Change-Id: I73a26b0d2f07bb624df6037e4e77f7137fd21791
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/VGridLayout.java | 4 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VSlider.java | 16 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/layout/VLayoutSlot.java | 37 |
3 files changed, 37 insertions, 20 deletions
diff --git a/client/src/com/vaadin/client/ui/VGridLayout.java b/client/src/com/vaadin/client/ui/VGridLayout.java index 90ae944322..d1e055eb5d 100644 --- a/client/src/com/vaadin/client/ui/VGridLayout.java +++ b/client/src/com/vaadin/client/ui/VGridLayout.java @@ -889,6 +889,10 @@ public class VGridLayout extends ComplexPanel { cell.slot.setCaption(null); cell.slot.getWrapperElement().removeFromParent(); cell.slot = null; + Style style = w.getElement().getStyle(); + style.clearTop(); + style.clearLeft(); + style.clearPosition(); if (cells.length < cell.col && cells.length != 0 && cells[0].length < cell.row diff --git a/client/src/com/vaadin/client/ui/VSlider.java b/client/src/com/vaadin/client/ui/VSlider.java index f5769ddf74..651880502c 100644 --- a/client/src/com/vaadin/client/ui/VSlider.java +++ b/client/src/com/vaadin/client/ui/VSlider.java @@ -201,7 +201,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, * applied to call code for parentElement only in case it exists. */ if (getElement().hasParentElement()) { - final Element p = getElement().getParentElement(); + final Element p = getElement(); if (p.getPropertyInt(domProperty) > MIN_SIZE) { if (isVertical()) { setHeight(); @@ -216,8 +216,10 @@ public class VSlider extends SimpleFocusablePanel implements Field, @Override public void execute() { - final Element p = getElement().getParentElement(); - if (p.getPropertyInt(domProperty) > (MIN_SIZE + 5)) { + final Element p = getElement(); + if (p.getPropertyInt(domProperty) > (MIN_SIZE + 5) + || propertyNotNullOrEmpty(styleAttribute, + p)) { if (isVertical()) { setHeight(); } else { @@ -227,6 +229,14 @@ public class VSlider extends SimpleFocusablePanel implements Field, setValue(value, false); } } + + // Style has non empty property + private boolean propertyNotNullOrEmpty( + final String styleAttribute, final Element p) { + return p.getStyle().getProperty(styleAttribute) != null + && !p.getStyle().getProperty(styleAttribute) + .isEmpty(); + } }); } } diff --git a/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java b/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java index 50020e51fe..5d463712df 100644 --- a/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java +++ b/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java @@ -69,6 +69,11 @@ public abstract class VLayoutSlot { public void setAlignment(AlignmentInfo alignment) { this.alignment = alignment; + // if alignment is something other than topLeft then we need to align + // the component inside this slot + if (alignment != null && (!alignment.isLeft() || !alignment.isTop())) { + widget.getElement().getStyle().setPosition(Position.ABSOLUTE); + } } public void positionHorizontally(double currentLocation, @@ -109,11 +114,7 @@ public abstract class VLayoutSlot { style.clearMarginRight(); } - if (isRelativeWidth()) { - style.setPropertyPx("width", (int) availableWidth); - } else { - style.clearProperty("width"); - } + style.setPropertyPx("width", (int) availableWidth); double allocatedContentWidth = 0; if (isRelativeWidth()) { @@ -124,6 +125,8 @@ public abstract class VLayoutSlot { reportActualRelativeWidth(Math.round((float) allocatedContentWidth)); } + style.setLeft(Math.round(currentLocation), Unit.PX); + double padding = 0; AlignmentInfo alignment = getAlignment(); if (!alignment.isLeft()) { double usedWidth; @@ -133,25 +136,26 @@ public abstract class VLayoutSlot { usedWidth = getWidgetWidth(); } if (alignment.isHorizontalCenter()) { - currentLocation += (allocatedSpace - usedWidth) / 2d; + padding = (allocatedSpace - usedWidth) / 2d; if (captionAboveCompnent) { captionStyle.setLeft( Math.round(usedWidth - captionWidth) / 2, Unit.PX); } } else { - currentLocation += (allocatedSpace - usedWidth); + padding = (allocatedSpace - usedWidth); if (captionAboveCompnent) { captionStyle.setLeft(Math.round(usedWidth - captionWidth), Unit.PX); } } + widget.getElement().getStyle() + .setLeft(Math.round(padding), Unit.PX); } else { if (captionAboveCompnent) { captionStyle.setLeft(0, Unit.PX); } } - style.setLeft(Math.round(currentLocation), Unit.PX); } private double parsePercent(String size) { @@ -184,11 +188,7 @@ public abstract class VLayoutSlot { style.clearMarginBottom(); } - if (isRelativeHeight()) { - style.setHeight(contentHeight, Unit.PX); - } else { - style.clearHeight(); - } + style.setHeight(contentHeight, Unit.PX); double allocatedContentHeight = 0; if (isRelativeHeight()) { @@ -199,6 +199,8 @@ public abstract class VLayoutSlot { .round((float) allocatedContentHeight)); } + style.setTop(currentLocation, Unit.PX); + double padding = 0; AlignmentInfo alignment = getAlignment(); if (!alignment.isTop()) { double usedHeight; @@ -208,13 +210,14 @@ public abstract class VLayoutSlot { usedHeight = getUsedHeight(); } if (alignment.isVerticalCenter()) { - currentLocation += (allocatedSpace - usedHeight) / 2d; + padding = (allocatedSpace - usedHeight) / 2d; } else { - currentLocation += (allocatedSpace - usedHeight); + padding = (allocatedSpace - usedHeight); } - } + padding += captionHeight; - style.setTop(currentLocation, Unit.PX); + widget.getElement().getStyle().setTop(padding, Unit.PX); + } } protected void reportActualRelativeHeight(int allocatedHeight) { |