Class UILabel

java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UILabel
All Implemented Interfaces:
Serializable

public class UILabel extends UIElement
Represents a label.
See Also:
  • Constructor Details

    • UILabel

      public UILabel()
      Creates a new, empty label.
    • UILabel

      public UILabel(String text)
      Creates a label containing the provided text.
      Parameters:
      text - the text you want to set for the label.
  • Method Details

    • setText

      public void setText(String text)
      Sets the text for the label.
      Parameters:
      text - the new text you want to set.
    • getText

      public String getText()
      Gets the currently set text of the label.
      Returns:
      the text of the label.
    • setRichTextEnabled

      public void setRichTextEnabled(boolean set)
      Determines whether or not rich text tags should be supported (e.g tags like "<color>" etc).
      Parameters:
      set - true to enable rich text tags (so they get parsed), false to disable them (so they will just be displayed like regular text). By default, rich text tags are enabled.
    • isRichTextEnabled

      public boolean isRichTextEnabled()
      Gets whether or not rich text is enabled and should be parsed.
      Returns:
      true if rich text should be parsed, false if not.
    • setFont

      public void setFont(Font font)
      Sets a new font for this label.

      Note: This is just a helper method. Internally it changes the style font property!
      Parameters:
      font - the new font you want to set for this label.
    • setFontSize

      public void setFontSize(float size)
      Sets a font size for the label.

      Note: This is just a helper method. Internally it changes the style fontSize property!
      Parameters:
      size - the new font size (pixels) you want to set for this label.
    • setFontSize

      public void setFontSize(float size, Unit unit)
      Sets a font size for the label.

      Note: This is just a helper method. Internally it changes the style fontSize property!
      Parameters:
      size - the new font size you want to set for this label.
      unit - determines if the size is in pixels (absolute) or percent (relative).
    • setFontColor

      public void setFontColor(float r, float g, float b, float a)
      Sets a font color for the label.

      Note: This is just a helper method. Internally it changes the style color property!
      Parameters:
      r - the new red component for the font color (0-1).
      g - the new green component for the font color (0-1).
      b - the new blue component for the font color (0-1).
      a - the new alpha component (opacity) for the font color (0-1).
    • setFontColor

      public void setFontColor(int rgba)
      Sets a font color for the label.

      Note: This is just a helper method. Internally it changes the style color property!
      Parameters:
      rgba - an int RGBA value describing the new color (e.g 0xFF0000FF for fully opaque red etc).
    • setTextAlign

      public void setTextAlign(TextAnchor anchor)
      Sets the alignment for the text.

      Note: This is just a helper method. Internally it changes the style textAlign property!
      Parameters:
      anchor - the anchor.
      Example: Set centered text
      1UILabel label = new UILabel("Hello World");
      2label.setBackgroundColor(0x000000FF);
      3label.setFontColor(0xFFFFFFFF);
      4label.setFontSize(32f);
      5label.setTextAlign(TextAnchor.MiddleCenter);
      6player.addUIElement(label);
    • setTextWrap

      public void setTextWrap(boolean wrap)
      Sets automatic text wrap for the label.

      Note: This is just a helper method. Internally it changes the style whiteSpace property!
      Parameters:
      wrap - true to enable automatic text wrapping, false to disable it.
    • setPivot

      public void setPivot(Pivot pivot)
      Description copied from class: UIElement
      Changes the origin of this element.

      Note: This is just a helper method. Internally it only changes the style transformOrigin and translate values!
      Overrides:
      setPivot in class UIElement
      Parameters:
      pivot - the new pivot/origin you want to set.