Package de.lessvoid.nifty.elements.render

Examples of de.lessvoid.nifty.elements.render.TextRenderer


      final Element element,
      final float normalizedTime,
      final Falloff falloff,
      final NiftyRenderEngine r) {
    if (targetElement != null) {
      TextRenderer textRenderer = targetElement.getRenderer(TextRenderer.class);
      textRenderer.setText(hintText);
      targetElement.setConstraintWidth(new SizeValue(textRenderer.getTextWidth() + "px"));
      nifty.getCurrentScreen().layoutLayers();
    }
  }
View Full Code Here


  }

  private void processLayoutInternal() {
    for (int i=0; i<elements.size(); i++) {
      Element w = elements.get(i);
      TextRenderer textRenderer = w.getRenderer(TextRenderer.class);
      if (textRenderer != null) {
        textRenderer.setWidthConstraint(w, w.getConstraintWidth(), getWidth(), nifty.getRenderEngine());
      }
    }
  }
View Full Code Here

  public void apply(
      final Element element,
      final Attributes attributes,
      final NiftyRenderEngine renderEngine) {
    TextRenderer textRenderer = element.getRenderer(TextRenderer.class);
    if (textRenderer == null) {
      return;
    }
    textRenderer.setFont(convert.font(renderEngine, attributes.get("font")));
    textRenderer.setTextHAlign(convert.textHorizontalAlign(attributes.get("textHAlign")));
    textRenderer.setTextVAlign(convert.textVerticalAlign(attributes.get("textVAlign")));
    textRenderer.setColor(convert.color(attributes.get("color")));
    textRenderer.setTextSelectionColor(convert.color(attributes.get("selectionColor")));
    textRenderer.setText(attributes.get("text"));
    textRenderer.setTextLineHeight(convert.sizeValue(attributes.get("textLineHeight")));
    textRenderer.setTextMinHeight(convert.sizeValue(attributes.get("textMinHeight")));
    boolean wrap = attributes.getAsBoolean("wrap", false);
    textRenderer.setLineWrapping(wrap);

    if (!wrap) {
      if (element.getConstraintWidth() == null) {
        element.setConstraintWidth(convert.sizeValue(textRenderer.getTextWidth() + "px"));
      }
      if (element.getConstraintHeight() == null) {
        element.setConstraintHeight(convert.sizeValue(textRenderer.getTextHeight() + "px"));
      }
    }
  }
View Full Code Here

  protected void makeFlat() {
    super.makeFlat();
    setTagName("<text>");
    setElementRendererCreator(new ElementRendererCreator() {
      public ElementRenderer[] createElementRenderer(final Nifty nifty) {
        TextRenderer textRenderer = new TextRenderer(nifty);
        ElementRenderer[] panelRenderer = nifty.getRootLayerFactory().createPanelRenderer();
        ElementRenderer[] renderer = new ElementRenderer[panelRenderer.length + 1];
        for (int i = 0; i < panelRenderer.length; i++) {
          renderer[i] = panelRenderer[i];
        }
View Full Code Here

    this.focusHandler = screen.getFocusHandler();

    this.textField.initWithText(textElement.getRenderer(TextRenderer.class).getOriginalText());
    this.fieldWidth = this.fieldElement.getWidth() - this.cursorElement.getWidth();

    TextRenderer textRenderer = textElement.getRenderer(TextRenderer.class);
    this.firstVisibleCharacterIndex = 0;
    this.lastVisibleCharacterIndex = FontHelper.getVisibleCharactersFromStart(textRenderer.getFont(), this.textField.getText(), fieldWidth, 1.0f);

    updateCursor();
    super.init(parameter, controlDefinitionAttributes);
  }
View Full Code Here

    textField.endSelecting();
    updateCursor();
  }

  private int getCursorPosFromMouse(final int mouseX, final String visibleString) {
    TextRenderer textRenderer = textElement.getRenderer(TextRenderer.class);
    return FontHelper.getCharacterIndexFromPixelPosition(textRenderer.getFont(), visibleString,
        (mouseX - fieldElement.getX()), 1.0f);
  }
View Full Code Here

    updateCursor();
    return false;
  }

  private void updateCursor() {
    TextRenderer textRenderer = textElement.getRenderer(TextRenderer.class);
    String text = textField.getText();
    checkBounds(text, textRenderer);
    calcLastVisibleIndex(textRenderer);

    // update text
    if (isPassword(passwordChar)) {
      int numChar = text.length();
      char[] chars = new char[numChar];
      for (int i = 0; i < numChar; ++i) {
        chars[i] = passwordChar;
      }
      text = new String(chars);
    }
    textRenderer.setText(text);
    textRenderer.setSelection(textField.getSelectionStart(), textField.getSelectionEnd());

    // calc cursor position
    int cursorPos = textField.getCursorPosition();

    // outside, move window to fit cursorPos inside [first,last]
    calcFirstVisibleIndex(cursorPos);
    calcLastVisibleIndex(textRenderer);

    String substring2 = text.substring(0, firstVisibleCharacterIndex);
    int d = textRenderer.getFont().getWidth(substring2);
    textRenderer.setXoffsetHack(-d);

    String substring = text.substring(0, cursorPos);
    int textWidth = textRenderer.getFont().getWidth(substring);
    int cursorPixelPos = textWidth - d;

    cursorElement.setConstraintX(new SizeValue(cursorPixelPos + "px"));
    cursorElement.setConstraintY(new SizeValue((getElement().getHeight() - cursorElement.getHeight()) / 2 + CURSOR_Y + "px"));
    cursorElement.startEffect(EffectEventId.onActive, null);
View Full Code Here

  public class SimpleDropDownViewConverter<T> implements DropDownViewConverter<T> {
    private Logger log = Logger.getLogger(SimpleDropDownViewConverter.class.getName());

    @Override
    public void display(final Element element, final T item) {
      TextRenderer renderer = element.getRenderer(TextRenderer.class);
      if (renderer == null) {
        log.warning(
              "you're using the SimpleDropDownViewConverter but there is no TextRenderer on the element."
            + "You've probably changed the item template but did not provided your own "
            + "DropDownViewConverter to the DropDown.");
        return;
      }
      if (item != null) {
        renderer.setText(item.toString());
      } else {
        renderer.setText("");
      }
    }
View Full Code Here

      }
    }

    @Override
    public int getWidth(final Element element, final T item) {
      TextRenderer renderer = element.getRenderer(TextRenderer.class);
      if (renderer == null) {
        log.warning(
            "you're using the SimpleDropDownViewConverter but there is no TextRenderer on the element."
          + "You've probably changed the item template but did not provided your own "
          + "DropDownViewConverter to the DropDown.");
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public final void display(final Element listBoxItem, final ChatEntryModelClass item) {
        final Element text = listBoxItem.findElementByName(CHAT_LINE_TEXT);
        final TextRenderer textRenderer = text.getRenderer(TextRenderer.class);
        final Element icon = listBoxItem.findElementByName(CHAT_LINE_ICON);
        final ImageRenderer iconRenderer = icon.getRenderer(ImageRenderer.class);
        if (item != null) {
            textRenderer.setText(item.toString());
            iconRenderer.setImage(item.getIcon());
        } else {
            textRenderer.setText("");
            iconRenderer.setImage(null);
        }
    }
View Full Code Here

TOP

Related Classes of de.lessvoid.nifty.elements.render.TextRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.