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())); }
builder.text(String.valueOf(item.getValue())); builder.textHAlign(ElementBuilder.Align.Left); builder.width(SizeValue.wildcard()); builder.build(text.getNifty(), screen, text);
builder.text(String.valueOf(item.getValue())); builder.textHAlign(ElementBuilder.Align.Left); builder.width(SizeValue.wildcard()); builder.build(text.getNifty(), screen, text);