Klasse UILabel

java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UILabel
Alle implementierten Schnittstellen:
Serializable

public class UILabel extends UIElement
Represents a label.
Example: Create a label in the upper center of the screen
1//Create label with text "Hello World"
2UILabel label = new UILabel("Hello World");
3
4//We want the text to be centered
5label.setTextAlign(TextAnchor.MiddleCenter);
6
7//Set a font, font size and color
8label.setFont(Font.Medieval);
9label.setFontSize(64f);
10label.setFontColor(0xFFFFFFFF);
11
12//Optionally set a background color
13label.setBackgroundColor(0x000000FF);
14
15//Add the UI element to the player
16player.addUIElement(label);
Siehe auch:
  • Konstruktordetails

    • UILabel

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

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

    • setText

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

      public String getText()
      Gets the currently set text of the label.
      Gibt zurück:
      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).
      Parameter:
      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.
      Gibt zurück:
      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!
      Parameter:
      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!
      Parameter:
      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!
      Parameter:
      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!
      Parameter:
      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!
      Parameter:
      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!
      Parameter:
      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!
      Parameter:
      wrap - true to enable automatic text wrapping, false to disable it.
    • setPivot

      public void setPivot(Pivot pivot)
      Beschreibung aus Klasse kopiert: UIElement
      Changes the origin of this element.

      Note: This is just a helper method. Internally it only changes the style transformOrigin and translate values!
      Setzt außer Kraft:
      setPivot in Klasse UIElement
      Parameter:
      pivot - the new pivot/origin you want to set.