/** * Create a percentage based size value. * * @param percentage percentage value * @return the size value instance representing the percentage value * @see de.lessvoid.nifty.tools.SizeValueType#Percent */ @Nonnull public static SizeValue percent(final int percentage) { return new SizeValue(percentage, SizeValueType.Percent); }
private int rightMargin(@Nonnull final BoxConstraints boxConstraints, final int rootBoxWidth) { return boxConstraints.getMarginRight().getValueAsInt(rootBoxWidth); }
public ChatBuilder chatLineHeight(@Nonnull final SizeValue value) { set("chatLineHeight", value.getValueAsString()); return this; } }
/** * default constructor. */ public BoxConstraints() { this.x = SizeValue.def(); this.y = SizeValue.def(); this.width = SizeValue.def(); this.height = SizeValue.def(); this.horizontalAlign = HorizontalAlign.horizontalDefault; this.verticalAlign = VerticalAlign.verticalDefault; paddingLeft = SizeValue.px(0); paddingRight = SizeValue.px(0); paddingTop = SizeValue.px(0); paddingBottom = SizeValue.px(0); marginLeft = SizeValue.px(0); marginRight = SizeValue.px(0); marginTop = SizeValue.px(0); marginBottom = SizeValue.px(0); }
public int insetSizeValue(@Nullable final String value, final int imageHeight) { if (value == null) { return 0; } SizeValue sizeValue = new SizeValue(value); return sizeValue.getValueAsInt(imageHeight); } }
private int getHorizontalHover(@Nonnull Element element) { return hoverWidth.hasValue() ? hoverWidth.getValueAsInt(element.getWidth()) : element.getWidth(); }
if (myHeight.hasDefault()) { List<LayoutPart> layoutPartChild = getLayoutChildrenWithIndependentHeight(); if (newHeight.hasValue()) { int newHeightPx = newHeight.getValueAsInt(0); newHeightPx += this.layoutPart.getBoxConstraints().getPaddingTop().getValueAsInt(newHeight.getValueAsInt (newHeightPx)); newHeightPx += this.layoutPart.getBoxConstraints().getPaddingBottom().getValueAsInt(newHeight .getValueAsInt(newHeightPx)); setConstraintHeight(SizeValue.def(newHeightPx)); setConstraintHeight(SizeValue.def()); } else if (myHeight.hasSum()) { 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 (newHeightPx)); newHeightPx += this.layoutPart.getBoxConstraints().getPaddingBottom().getValueAsInt(newHeight.getValueAsInt (newHeightPx)); setConstraintHeight(SizeValue.sum(newHeightPx)); } else { setConstraintHeight(SizeValue.sum(0)); } else if (myHeight.hasMax()) { List<LayoutPart> layoutPartChild = getLayoutChildrenWithIndependentHeight(); SizeValue newHeight = layoutPart.getMaxHeight(layoutPartChild);
private void initializeScrollElementHeight() { if (scrollElement != null) { scrollElement.setConstraintHeight(SizeValue.px(displayItems * labelTemplateHeight)); } }
public void setWidthConstraint( @Nonnull final Element element, @Nonnull final SizeValue elementConstraintWidth, final int parentWidth, @Nonnull final NiftyRenderEngine renderEngine) { if (parentWidth == 0 || !lineWrapping || isCalculatedLineWrapping) { return; } int valueAsInt = element.getWidth(); if (valueAsInt == 0) { valueAsInt = elementConstraintWidth.getValueAsInt(parentWidth); } if (valueAsInt <= 0) { return; } // remember some values so that we can correctly do auto word wrapping when someone changes the text this.hasBeenLayoutedElement = element; this.textLines = wrapText(valueAsInt, renderEngine, originalText.split("\n", -1)); maxWidth = valueAsInt; // we'll now modify the element constraints so that the layout mechanism can later take this word wrapping // business correctly into account when the elements will be layouted. to make sure we're able to reset this // effect later, we'll remember that we've artificially calculated those values in here. so that we're able to // actually reset this later. isCalculatedLineWrapping = true; originalConstraintWidth = element.getConstraintWidth(); originalConstraintHeight = element.getConstraintHeight(); element.setConstraintWidth( elementConstraintWidth.hasWildcard() ? SizeValue.wildcard(getTextWidth()) : SizeValue.px(getTextWidth())); element.setConstraintHeight(SizeValue.px(getTextHeight())); }
public void forward() { int cX = content.getConstraintX().getValueAsInt(1.f); if (cX < 0) { content.setConstraintX(SizeValue.px(cX + stepSize)); content.getParent().layoutElements(); } }
log.warning("Spacing area used for indenting of the tree was not found. Looked for: #tree-item-spacer"); } else { spacer.setConstraintWidth(SizeValue.px(item.getIndent())); spacer.setConstraintHeight(SizeValue.px(1)); spacer.setVisible(item.getIndent() > 0); builder.text(String.valueOf(item.getValue())); builder.textHAlign(ElementBuilder.Align.Left); builder.width(SizeValue.wildcard()); builder.build(text.getNifty(), screen, text);
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{ box.setY(0); //to handle when a previous setY was done and you want to set back to default if (cons.getWidth().hasHeightSuffix()) { if (cons.getHeight().hasValue()) { box.setHeight(cons.getHeight().getValueAsInt(rootBoxHeight)); box.setWidth(cons.getWidth().getValueAsInt(box.getHeight())); } else if (cons.getHeight().hasWidthSuffix()) { if (cons.getWidth().hasValue()) { box.setWidth(cons.getWidth().getValueAsInt(rootBoxWidth)); box.setHeight(cons.getHeight().getValueAsInt(box.getWidth())); } else { if (cons.getWidth().hasValue()) { box.setWidth(cons.getWidth().getValueAsInt(rootBoxWidth)); }else{ box.setWidth(0); if (cons.getHeight().hasValue()) { box.setHeight(cons.getHeight().getValueAsInt(rootBoxHeight)); }else{
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); }
private int processWidthConstraints( final int rootBoxWidth, @Nonnull final BoxConstraints constraints, final int elementHeight) { if (hasWidthConstraint(constraints)) { if (constraints.getWidth().hasHeightSuffix()) { return constraints.getWidth().getValueAsInt(elementHeight); } return constraints.getWidth().getValueAsInt(rootBoxWidth); } else { return rootBoxWidth; } }
@Override public void activate( @Nonnull final Nifty niftyParam, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { nifty = niftyParam; music = nifty.getSoundSystem().getMusic(parameter.getProperty("sound")); if (music == null) { log.warning("Failed to get music for effect."); } else { fromVolume = new SizeValue(parameter.getProperty("from", "0%")).getValue(1.0f); toVolume = new SizeValue(parameter.getProperty("to", "100%")).getValue(1.0f); } }
private int processHeightConstraint( final int rootBoxHeight, final Box box, @Nonnull final BoxConstraints constraint, final int elementWidth) { if (hasHeightConstraint(constraint)) { if (constraint.getHeight().hasWidthSuffix()) { return constraint.getHeight().getValueAsInt(elementWidth); } return constraint.getHeight().getValueAsInt(rootBoxHeight); } else { return rootBoxHeight; } }
private void layoutElement( @Nonnull final LayoutPart element, @Nonnull Box rootBox, @Nonnull BoxConstraints rootBoxConstraints) { Box box = element.getBox(); BoxConstraints constraint = element.getBoxConstraints(); if (constraint.getWidth().hasHeightSuffix()) { handleVerticalAlignment(rootBox, rootBoxConstraints, box, constraint); handleHorizontalAlignment(rootBox, rootBoxConstraints, box, constraint); } else if (constraint.getHeight().hasWidthSuffix()) { handleHorizontalAlignment(rootBox, rootBoxConstraints, box, constraint); handleVerticalAlignment(rootBox, rootBoxConstraints, box, constraint); } else { handleVerticalAlignment(rootBox, rootBoxConstraints, box, constraint); handleHorizontalAlignment(rootBox, rootBoxConstraints, box, constraint); } box.setX(box.getX() + leftMargin(constraint, rootBox.getWidth()) - rightMargin(constraint, rootBox.getWidth())); box.setY(box.getY() + topMargin(constraint, rootBox.getHeight()) - bottomMargin(constraint, rootBox.getHeight())); }
if (element.getConstraintWidth().hasDefault()) { element.setConstraintWidth(SizeValue.def(imageDimension.getWidth())); if (element.getConstraintHeight().hasDefault()) { element.setConstraintHeight(SizeValue.def(imageDimension.getHeight()));
/** * @param children children elements of the root element * @return new calculated SizeValue */ @Nonnull @Override public final SizeValue calculateConstraintHeight( @Nonnull final LayoutPart root, @Nonnull final List<LayoutPart> children) { return SizeValue.def(); } }
/** * execute the effect. * * @param element the Element * @param normalizedTime TimeInterpolator to use * @param normalizedFalloff falloff value * @param r RenderDevice to use */ @Override public void execute( @Nonnull final Element element, final float normalizedTime, @Nullable final Falloff falloff, @Nonnull final NiftyRenderEngine r) { if (!activated && normalizedTime > 0.0f) { activated = true; pulsator.reset(); } if (activated) { float value = pulsator.update(); float size = startSize.getValue(1.0f) + value * (endSize.getValue(1.0f) - startSize.getValue(1.0f)); r.setImageScale(size); } }