Search in sources :

Example 1 with AlignmentInfo

use of com.vaadin.shared.ui.AlignmentInfo in project cuba by cuba-platform.

the class CubaFieldGroupLayoutComponentSlot method positionVertically.

@Override
public void positionVertically(double currentLocation, double allocatedSpace, double marginBottom) {
    if (!isCaptionInline()) {
        super.positionVertically(currentLocation, allocatedSpace, marginBottom);
        return;
    }
    // CAUTION copied from VLayoutSlot.positionVertically(~)
    Style style = wrapper.getStyle();
    double contentHeight = allocatedSpace;
    int captionHeight;
    VCaption caption = getCaption();
    if (caption == null || caption.shouldBePlacedAfterComponent() || isCaptionInline()) {
        style.clearPaddingTop();
        captionHeight = 0;
    } else {
        captionHeight = getCaptionHeight();
        contentHeight -= captionHeight;
        if (contentHeight < 0) {
            contentHeight = 0;
        }
        style.setPaddingTop(captionHeight, Style.Unit.PX);
    }
    if (marginBottom > 0) {
        style.setMarginBottom(marginBottom, Style.Unit.PX);
    } else {
        style.clearMarginBottom();
    }
    if (isRelativeHeight()) {
        style.setHeight(contentHeight, Style.Unit.PX);
    } else {
        style.clearHeight();
    }
    double allocatedContentHeight = 0;
    if (isRelativeHeight()) {
        String height = getWidget().getElement().getStyle().getHeight();
        double percentage = parsePercent(height);
        allocatedContentHeight = contentHeight * (percentage / 100);
        reportActualRelativeHeight(Math.round((float) allocatedContentHeight));
    }
    AlignmentInfo alignment = getAlignment();
    if (!alignment.isTop()) {
        double usedHeight;
        if (isRelativeHeight()) {
            if (isCaptionInline()) {
                usedHeight = allocatedContentHeight;
            } else {
                usedHeight = captionHeight + allocatedContentHeight;
            }
        } else {
            usedHeight = getUsedHeight();
        }
        if (alignment.isVerticalCenter()) {
            currentLocation += (allocatedSpace - usedHeight) / 2d;
        } else {
            currentLocation += (allocatedSpace - usedHeight);
        }
    }
    style.setTop(currentLocation, Style.Unit.PX);
}
Also used : Style(com.google.gwt.dom.client.Style) AlignmentInfo(com.vaadin.shared.ui.AlignmentInfo) VCaption(com.vaadin.client.VCaption)

Example 2 with AlignmentInfo

use of com.vaadin.shared.ui.AlignmentInfo in project cuba by cuba-platform.

the class CubaFieldGroupLayoutComponentSlot method positionHorizontally.

@Override
public void positionHorizontally(double currentLocation, double allocatedSpace, double marginRight) {
    if (!isCaptionInline()) {
        super.positionHorizontally(currentLocation, allocatedSpace, marginRight);
        return;
    }
    // CAUTION copied from VLayoutSlot.positionHorizontally(~)
    Style style = wrapper.getStyle();
    double availableWidth = allocatedSpace;
    VCaption caption = getCaption();
    Style captionStyle = caption != null ? caption.getElement().getStyle() : null;
    int captionWidth = getCaptionWidth();
    boolean clearCaptionRight = false;
    boolean captionAboveCompnent;
    if (caption == null) {
        captionAboveCompnent = false;
        style.clearPaddingLeft();
        clearCaptionRight = true;
    } else {
        captionAboveCompnent = !caption.shouldBePlacedAfterComponent();
        if (!captionAboveCompnent) {
            availableWidth -= captionWidth;
            if (availableWidth < 0) {
                availableWidth = 0;
            }
            captionStyle.clearLeft();
            captionStyle.setRight(0, Style.Unit.PX);
            style.setPaddingRight(captionWidth, Style.Unit.PX);
        } else {
            availableWidth -= captionWidth;
            if (availableWidth < 0) {
                availableWidth = 0;
            }
            style.setPaddingLeft(captionWidth, Style.Unit.PX);
            captionStyle.setLeft(0, Style.Unit.PX);
            captionStyle.clearRight();
            clearCaptionRight = true;
        }
    }
    // Take into account right indicators
    double indicatorsWidth = 0;
    if (rightCaption != null) {
        indicatorsWidth = WidgetUtil.getRequiredWidth(rightCaption);
        availableWidth -= indicatorsWidth;
        if (availableWidth < 0) {
            availableWidth = 0;
        }
        style.setPaddingRight(indicatorsWidth, Style.Unit.PX);
    } else if (clearCaptionRight) {
        style.clearPaddingRight();
    }
    if (marginRight > 0) {
        style.setMarginRight(marginRight, Style.Unit.PX);
    } else {
        style.clearMarginRight();
    }
    if (isRelativeWidth()) {
        style.setPropertyPx("width", (int) availableWidth);
    } else {
        style.clearProperty("width");
    }
    double allocatedContentWidth = 0;
    if (isRelativeWidth()) {
        String percentWidth = getWidget().getElement().getStyle().getWidth();
        double percentage = parsePercent(percentWidth);
        allocatedContentWidth = availableWidth * (percentage / 100);
        reportActualRelativeWidth(Math.round((float) allocatedContentWidth));
    }
    AlignmentInfo alignment = getAlignment();
    if (!alignment.isLeft()) {
        double usedWidth;
        if (isRelativeWidth()) {
            if (isCaptionInline()) {
                usedWidth = allocatedContentWidth + indicatorsWidth + captionWidth;
            } else {
                usedWidth = allocatedContentWidth + indicatorsWidth;
            }
        } else {
            usedWidth = getWidgetWidth() + indicatorsWidth;
        }
        if (alignment.isHorizontalCenter()) {
            currentLocation += (allocatedSpace - usedWidth) / 2d;
            if (captionAboveCompnent) {
                captionStyle.setLeft(Math.round(usedWidth - captionWidth) / 2, Style.Unit.PX);
            }
        } else {
            currentLocation += (allocatedSpace - usedWidth);
            if (captionAboveCompnent) {
                captionStyle.setLeft(Math.round(usedWidth - captionWidth), Style.Unit.PX);
            }
        }
    } else {
        if (captionAboveCompnent) {
            captionStyle.setLeft(0, Style.Unit.PX);
        }
    }
    style.setLeft(Math.round(currentLocation), Style.Unit.PX);
}
Also used : Style(com.google.gwt.dom.client.Style) AlignmentInfo(com.vaadin.shared.ui.AlignmentInfo) VCaption(com.vaadin.client.VCaption)

Aggregations

Style (com.google.gwt.dom.client.Style)2 VCaption (com.vaadin.client.VCaption)2 AlignmentInfo (com.vaadin.shared.ui.AlignmentInfo)2