Class GUILabel

java.lang.Object
com.blackrook.gui.GUIObject
com.blackrook.gui.object.GUILabel
Direct Known Subclasses:
GUICycler

public class GUILabel extends GUIObject
GUI Object that holds and displays text data.
Author:
Matthew Tropiano
  • Constructor Details

    • GUILabel

      public GUILabel()
      Creates a new GUI Text object with no text nor specific font.
    • GUILabel

      public GUILabel(String text)
      Creates a new GUI Text object (with no specified font).
      Parameters:
      text - the initial text.
    • GUILabel

      public GUILabel(GUIFontType font)
      Creates a new GUI Text object.
      Parameters:
      font - the specific font to use.
    • GUILabel

      public GUILabel(GUIFontType font, String text)
      Creates a new GUI Text object.
      Parameters:
      font - the specific font to use.
      text - the initial text.
    • GUILabel

      public GUILabel(GUIFontType font, String text, GUILabel.Justification justification)
      Creates a new GUI Text object.
      Parameters:
      font - the specific font to use.
      text - the initial text.
      justification - the text justification.
    • GUILabel

      public GUILabel(GUIFontType font, String text, GUILabel.Justification justification, GUILabel.Alignment alignment)
      Creates a new GUI Text object.
      Parameters:
      font - the specific font to use.
      text - the initial text.
      justification - the text justification.
      alignment - the text line alignment.
  • Method Details

    • setBounds

      public GUIObject setBounds(float x, float y, float width, float height)
      Sets the object bounds.
      Overrides:
      setBounds in class GUIObject
      Parameters:
      x - its position x.
      y - its position y.
      width - its width.
      height - its height.
      Returns:
      itself, to chain calls.
    • stretch

      public GUIObject stretch(float width, float height)
      Changes this object's width/height by an x or y-coordinate amount.
      Overrides:
      stretch in class GUIObject
      Parameters:
      width - the width amount.
      height - the height amount.
      Returns:
      itself, to chain calls.
    • getTexture

      public String getTexture()
      Gets this object's texture, which is taken from the selected font. If no font is set on this, this will take the one from the theme, if this also has a theme key set on it.
      Overrides:
      getTexture in class GUIObject
      Returns:
      the most relevant texture to use, null if none suitable.
      See Also:
    • setTheme

      public GUIObject setTheme(GUITheme theme)
      Description copied from class: GUIObject
      Sets the theme used by this object, and its descendants if they do not have a theme set. Setting this to null allows this object to inherit the current theme from its parents.
      Overrides:
      setTheme in class GUIObject
      Parameters:
      theme - the theme to use. Can be null.
      Returns:
      itself, to chain calls.
    • getFont

      public GUIFontType getFont()
      Gets the font for this text object. If no font is set on this object, it will attempt to get it from the theme, if the appropriate theme key is set.
      Returns:
      the font to use for rendering text.
    • setFont

      public GUILabel setFont(GUIFontType font)
      Sets the font for this text object.
      Parameters:
      font - the font for the label.
      Returns:
      itself, to chain calls.
    • getSize

      public float getSize()
      Returns:
      the size of the font in GUI units.
    • setSize

      public GUILabel setSize(float size)
      Sets the size of the font in GUI units.
      Parameters:
      size - the new size.
      Returns:
      itself, to chain calls.
    • getThemeKey

      public String getThemeKey()
      Description copied from class: GUIObject
      Returns this object's theme key. This is the key that is used to look up the texture used to render this object. This may return null, indicating that this object does not have a default texture.
      Specified by:
      getThemeKey in class GUIObject
      Returns:
      the theme key.
    • setThemeKey

      public GUILabel setThemeKey(String themeKey)
      Sets this object's theme key. This is the key that is used to look up the font used to render this object if a theme is applied to this object or the GUI that owns it.
      Parameters:
      themeKey - the theme key to use.
      Returns:
      itself, to chain calls.
    • getText

      public String getText()
      Gets the text on this text object. Default is the empty string.
      Returns:
      the text.
    • setText

      public GUILabel setText(String text)
      Sets the text on this text object. Default is the empty string.
      Parameters:
      text - the text to set.
      Returns:
      itself, to chain calls.
    • isWordWrapping

      public boolean isWordWrapping()
      Checks if word wrapping is enabled.
      Returns:
      true if so, false if not.
    • setWordWrapping

      public GUILabel setWordWrapping(boolean wordWrap)
      Sets if word wrapping is enabled. True if so, false if not.
      Parameters:
      wordWrap -
      Returns:
      itself, to chain calls.
    • getJustification

      public GUILabel.Justification getJustification()
      Returns:
      the text alignment/justification.
    • setJustification

      public GUILabel setJustification(GUILabel.Justification justification)
      Sets the text alignment/justification.
      Parameters:
      justification - the justification to use.
      Returns:
      itself, to chain calls.
    • getAlignment

      public GUILabel.Alignment getAlignment()
      Returns:
      the current style of vertical text alignment.
    • setAlignment

      public GUILabel setAlignment(GUILabel.Alignment alignment)
      Sets the current style of vertical text alignment.
      Parameters:
      alignment - the text alignment to use.
      Returns:
      itself, to chain calls.
    • getResizeMode

      public GUILabel.ResizeMode getResizeMode()
      Gets the current resize mode for this text object. If this is not null, the object will resize itself according to the max width and resize mode parameters.
      Returns:
      the current resize mode.
    • setResizeMode

      public GUILabel setResizeMode(GUILabel.ResizeMode resizeMode)
      Sets the current resize mode for this text object. If this is not null, the object will resize itself according to the max width and resize mode parameters.
      Parameters:
      resizeMode - the resize mode.
      Returns:
      itself, to chain calls.
    • getMaxWidth

      public float getMaxWidth()
      Returns:
      the max width in units for the resizing capability of this object.
    • setMaxWidth

      public GUILabel setMaxWidth(float maxWidth)
      Sets the max width in units for the resizing capability of this object.
      Parameters:
      maxWidth - the max width in units.
      Returns:
      itself, to chain calls.
    • getStartingLine

      public int getStartingLine()
      Gets the starting line that the mesh data will be generated for in the text field. By default, this is zero (first line).
      Returns:
      the starting line index.
    • setStartingLine

      public GUILabel setStartingLine(int startingLine)
      Sets the starting line that the mesh data will be generated for in the text field. By default, this is zero (first line).
      Parameters:
      startingLine - the starting line index.
      Returns:
      itself, to chain calls.
    • getTextPiece

      public GUILabel.TextPiece getTextPiece(int index)
      Gets a single piece of the rendered text data for rendering.
      Parameters:
      index - the character index.
      Returns:
      a piece of text, or null if no corresponding piece.
    • getTextPieceCount

      public int getTextPieceCount()
      Returns:
      get text piece count.
    • onGUIChange

      protected void onGUIChange(GUI gui)
      Description copied from class: GUIObject
      Called when this object is added to a GUI. Does nothing, unless overridden.
      Overrides:
      onGUIChange in class GUIObject
      Parameters:
      gui - the reference to the GUI that this was added to.