/** * Checks if this value describes a percent value. * * @return true if the given string value ends with PERCENT * and false otherwise. */ public boolean isPercent() { if (!hasValue()) { return false; } switch (type) { case Percent: case PercentWidth: case PercentHeight: return true; default: return false; } }
/** * Check if the size value contains a value either in percent or pixel. * * @return {@code true} in case its a pixel or percent value * @deprecated function got renamed to {@link #hasValue()} */ @Deprecated public boolean isPercentOrPixel() { return hasValue(); }
/** * Checks if this value describes a pixel value. * * @return true if the given string value ends with PIXEL * and false otherwise */ public boolean isPixel() { return hasValue() && !isPercent(); }
private boolean hasHeightConstraint(@Nullable final BoxConstraints boxConstraints) { return boxConstraints != null && boxConstraints.getHeight().hasValue(); }
private boolean hasHeightConstraint(@Nullable final BoxConstraints constraint) { return constraint != null && constraint.getHeight().hasValue(); }
private boolean hasWidthConstraint(@Nullable final BoxConstraints constraint) { return constraint != null && constraint.getWidth().hasValue(); }
private int getHorizontalHover(@Nonnull Element element) { return hoverWidth.hasValue() ? hoverWidth.getValueAsInt(element.getWidth()) : element.getWidth(); }
private int getVerticalHover(@Nonnull Element element) { return hoverHeight.hasValue() ? hoverHeight.getValueAsInt(element.getHeight()) : element.getHeight(); }
private int getMaxNonFixedHeight(@Nonnull final List<LayoutPart> elements, final int parentHeight) { int maxFixedHeight = 0; int fixedCount = 0; for (int i = 0; i < elements.size(); i++) { LayoutPart p = elements.get(i); BoxConstraints original = p.getBoxConstraints(); if (hasHeightConstraint(original)) { if (original.getHeight().hasValue()) { maxFixedHeight += original.getHeight().getValueAsInt(parentHeight); fixedCount++; } } } int notFixedCount = elements.size() - fixedCount; if (notFixedCount > 0) { return (parentHeight - maxFixedHeight) / notFixedCount; } else { return (parentHeight - maxFixedHeight); } }
/** * @param elements the child elements the max width is going * to be calculated * @param parentWidth the width of the parent element * @return max non fixed width */ private int getMaxNonFixedWidth( @Nonnull final List<LayoutPart> elements, final int parentWidth ) { int maxFixedWidth = 0; int fixedCount = 0; for (int i = 0; i < elements.size(); i++) { LayoutPart p = elements.get(i); BoxConstraints original = p.getBoxConstraints(); if (original.getWidth().hasValue()) { maxFixedWidth += original.getWidth().getValueAsInt(parentWidth); fixedCount++; } } int notFixedCount = elements.size() - fixedCount; if (notFixedCount > 0) { return (parentWidth - maxFixedWidth) / notFixedCount; } else { return (parentWidth - maxFixedWidth); } }
/** * Helper method to get height of text. * * @return the height in pixel of the current set text. */ public int getTextHeight() { RenderFont font = ensureFont(nifty.getRenderEngine()); if (font == null || textLines == null) { return 0; } int calculatedHeight = font.getHeight() * textLines.length; if (textLineHeight.hasValue()) { calculatedHeight = textLineHeight.getValueAsInt(1.0f) * textLines.length; } if (textMinHeight.hasValue()) { if (calculatedHeight < textMinHeight.getValueAsInt(1.0f)) { return textMinHeight.getValueAsInt(1.0f); } } return calculatedHeight; }
private int calcElementWidth( @Nonnull final List<LayoutPart> children, final int rootBoxWidth, @Nonnull final BoxConstraints boxConstraints, final int elementHeight) { if (boxConstraints.getWidth().hasValue()) { int h = boxConstraints.getWidth().getValueAsInt(rootBoxWidth); if (boxConstraints.getWidth().hasHeightSuffix()) { h = boxConstraints.getWidth().getValueAsInt(elementHeight); } if (h != -1) { return h; } } return getMaxNonFixedWidth(children, rootBoxWidth); }
void handleHorizontalAlignment( @Nonnull final Box rootBox, @Nonnull final BoxConstraints rootBoxConstraints, @Nonnull final Box box, @Nonnull final BoxConstraints constraint) { if (constraint.getWidth().hasValue()) { handleWidthConstraint(rootBox, rootBoxConstraints, box, constraint); } else { box.setX( rootBox.getX() + rootBoxConstraints.getPaddingLeft().getValueAsInt(rootBox.getWidth())); box.setWidth( rootBox.getWidth() - rootBoxConstraints.getPaddingLeft().getValueAsInt(rootBox.getWidth()) - rootBoxConstraints.getPaddingRight().getValueAsInt(rootBox.getWidth())); } }
void handleVerticalAlignment( @Nonnull final Box rootBox, @Nonnull final BoxConstraints rootBoxConstraints, @Nonnull final Box box, @Nonnull final BoxConstraints constraint) { if (constraint.getHeight().hasValue()) { handleHeightConstraint(rootBox, rootBoxConstraints, box, constraint); } else { box.setY( rootBox.getY() + rootBoxConstraints.getPaddingTop().getValueAsInt(rootBox.getHeight())); box.setHeight( rootBox.getHeight() - rootBoxConstraints.getPaddingTop().getValueAsInt(rootBox.getHeight()) - rootBoxConstraints.getPaddingBottom().getValueAsInt(rootBox.getHeight())); } }
if (cons.getX().hasValue()) { box.setX(rootBoxX + cons.getX().getValueAsInt(rootBoxWidth)); }else{ box.setX(0);//to handle when a previous setX was done and you want to set back to default if (cons.getY().hasValue()) { box.setY(rootBoxY + cons.getY().getValueAsInt(rootBoxHeight)); }else{ if (cons.getHeight().hasValue()) { box.setHeight(cons.getHeight().getValueAsInt(rootBoxHeight)); if (cons.getWidth().hasValue()) { box.setWidth(cons.getWidth().getValueAsInt(rootBoxWidth)); if (cons.getWidth().hasValue()) { box.setWidth(cons.getWidth().getValueAsInt(rootBoxWidth)); }else{ if (cons.getHeight().hasValue()) { box.setHeight(cons.getHeight().getValueAsInt(rootBoxHeight)); }else{
if (newHeight.hasValue()) { int newHeightPx = newHeight.getValueAsInt(0); newHeightPx += this.layoutPart.getBoxConstraints().getPaddingTop().getValueAsInt(newHeight.getValueAsInt List<LayoutPart> layoutPartChild = getLayoutChildrenWithIndependentHeight(); SizeValue newHeight = layoutPart.getSumHeight(layoutPartChild); if (newHeight.hasValue()) { int newHeightPx = newHeight.getValueAsInt(0); newHeightPx += this.layoutPart.getBoxConstraints().getPaddingTop().getValueAsInt(newHeight.getValueAsInt List<LayoutPart> layoutPartChild = getLayoutChildrenWithIndependentHeight(); SizeValue newHeight = layoutPart.getMaxHeight(layoutPartChild); if (newHeight.hasValue()) { int newHeightPx = newHeight.getValueAsInt(0); newHeightPx += this.layoutPart.getBoxConstraints().getPaddingTop().getValueAsInt(newHeight.getValueAsInt
if (newWidth.hasValue()) { int newWidthPx = newWidth.getValueAsInt(0); newWidthPx += this.layoutPart.getBoxConstraints().getPaddingLeft().getValueAsInt(newWidth.getValueAsInt List<LayoutPart> layoutPartChild = getLayoutChildrenWithIndependentWidth(); SizeValue newWidth = layoutPart.getSumWidth(layoutPartChild); if (newWidth.hasValue()) { int newWidthPx = newWidth.getValueAsInt(0); newWidthPx += this.layoutPart.getBoxConstraints().getPaddingLeft().getValueAsInt(newWidth.getValueAsInt List<LayoutPart> layoutPartChild = getLayoutChildrenWithIndependentWidth(); SizeValue newWidth = layoutPart.getMaxWidth(layoutPartChild); if (newWidth.hasValue()) { int newWidthPx = newWidth.getValueAsInt(0); newWidthPx += this.layoutPart.getBoxConstraints().getPaddingLeft().getValueAsInt(newWidth.getValueAsInt