Class WLabel

java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WLabel

public class WLabel extends WWidget
A single-line label widget.
  • Field Details

    • text

      protected Text text
    • horizontalAlignment

      protected HorizontalAlignment horizontalAlignment
    • verticalAlignment

      protected VerticalAlignment verticalAlignment
    • color

      protected int color
    • darkmodeColor

      protected int darkmodeColor
    • drawShadows

      protected boolean drawShadows
    • DEFAULT_TEXT_COLOR

      public static final int DEFAULT_TEXT_COLOR
      The default text color for light mode labels.
      See Also:
    • DEFAULT_DARKMODE_TEXT_COLOR

      public static final int DEFAULT_DARKMODE_TEXT_COLOR
      The default text color for dark mode labels.
      See Also:
  • Constructor Details

    • WLabel

      public WLabel(Text text, int color)
      Constructs a new label.
      Parameters:
      text - the text of the label
      color - the color of the label
    • WLabel

      public WLabel(Text text)
      Constructs a new label with the default text color.
      Parameters:
      text - the text of the label
      Since:
      1.8.0
  • Method Details

    • paint

      @Environment(CLIENT) public void paint(DrawContext context, int x, int y, int mouseX, int mouseY)
      Description copied from class: WWidget
      Paints this widget.
      Overrides:
      paint in class WWidget
      Parameters:
      context - the draw context
      x - this widget's X coordinate on the screen
      y - this widget's Y coordinate on the screen
      mouseX - the X coordinate of the cursor
      mouseY - the X coordinate of the cursor
    • onClick

      @Environment(CLIENT) public InputResult onClick(int x, int y, int button)
      Description copied from class: WWidget
      Notifies this widget that the mouse has been pressed and released, both while inside its bounds.
      Overrides:
      onClick in class WWidget
      Parameters:
      x - The X coordinate of the event, in widget-space (0 is the left edge of this widget)
      y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)
      button - The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • getTextStyleAt

      @Environment(CLIENT) @Nullable public @Nullable Style getTextStyleAt(int x, int y)
      Gets the text style at the specific widget-space coordinates.
      Parameters:
      x - the X coordinate in widget space
      y - the Y coordinate in widget space
      Returns:
      the text style at the position, or null if not found
    • canResize

      public boolean canResize()
      Description copied from class: WWidget
      Checks whether this widget can be resized using WWidget.setSize(int, int).
      Overrides:
      canResize in class WWidget
      Returns:
      true if this widget can be resized, false otherwise
    • setSize

      public void setSize(int x, int y)
      Description copied from class: WWidget
      Sets the size of this widget.

      Overriding methods may restrict one of the dimensions to be a constant value, for example super.setSize(x, 20).

      Overrides:
      setSize in class WWidget
      Parameters:
      x - the new width
      y - the new height
    • getDarkmodeColor

      public int getDarkmodeColor()
      Gets the dark mode color of this label.
      Returns:
      the color
      Since:
      2.0.0
    • setDarkmodeColor

      public WLabel setDarkmodeColor(int color)
      Sets the dark mode color of this label.
      Parameters:
      color - the new color
      Returns:
      this label
    • disableDarkmode

      public WLabel disableDarkmode()
      Disables separate dark mode coloring by copying the dark color to be the light color.
      Returns:
      this label
    • getColor

      public int getColor()
      Gets the light mode color of this label.
      Returns:
      the color
    • setColor

      public WLabel setColor(int color)
      Sets the light mode color of this label.
      Parameters:
      color - the new color
      Returns:
      this label
    • setColor

      public WLabel setColor(int color, int darkmodeColor)
      Sets the light and dark mode colors of this label.
      Parameters:
      color - the new light color
      darkmodeColor - the new dark color
      Returns:
      this label
    • getDrawShadows

      public boolean getDrawShadows()
      Checks whether shadows should be drawn for this label.
      Returns:
      true shadows should be drawn, false otherwise
      Since:
      11.1.0
    • setDrawShadows

      public WLabel setDrawShadows(boolean drawShadows)
      Sets whether shadows should be drawn for this label.
      Parameters:
      drawShadows - true if shadows should be drawn, false otherwise
      Returns:
      this label
      Since:
      11.1.0
    • getText

      public Text getText()
      Gets the text of this label.
      Returns:
      the text
    • setText

      public WLabel setText(Text text)
      Sets the text of this label.
      Parameters:
      text - the new text
      Returns:
      this label
    • getHorizontalAlignment

      public HorizontalAlignment getHorizontalAlignment()
      Gets the horizontal text alignment of this label.
      Returns:
      the alignment
      Since:
      2.0.0
    • setHorizontalAlignment

      public WLabel setHorizontalAlignment(HorizontalAlignment align)
      Sets the horizontal text alignment of this label.
      Parameters:
      align - the new text alignment
      Returns:
      this label
    • getVerticalAlignment

      public VerticalAlignment getVerticalAlignment()
      Gets the vertical text alignment of this label.
      Returns:
      the alignment
      Since:
      2.0.0
    • setVerticalAlignment

      public WLabel setVerticalAlignment(VerticalAlignment align)
      Sets the vertical text alignment of this label.
      Parameters:
      align - the new text alignment
      Returns:
      this label
    • addNarrations

      @Environment(CLIENT) public void addNarrations(NarrationMessageBuilder builder)
      Description copied from class: WWidget
      Adds the narrations of this widget to a narration builder. Narrations will only apply if this widget is narratable.

      The widget needs to be focusable or hoverable, and also be focused/hovered for narrations to be added.

      Overrides:
      addNarrations in class WWidget
      Parameters:
      builder - the narration builder, cannot be null