Class WDynamicLabel

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

public class WDynamicLabel extends WWidget
Dynamic labels are labels that pull their text from a Supplier<String>. They can be used for automatically getting data from a block entity or another data source.

Translating strings in dynamic labels should be done using I18n.translate(String, Object...).

  • Field Details

    • text

      protected Supplier<String> text
    • alignment

      protected HorizontalAlignment alignment
    • 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

    • WDynamicLabel

      public WDynamicLabel(Supplier<String> text, int color)
      Constructs a new dynamic label.
      Parameters:
      text - the text of the label
      color - the color of the label
    • WDynamicLabel

      public WDynamicLabel(Supplier<String> text)
      Constructs a new dynamic label with the default text color.
      Parameters:
      text - the text of the label
  • 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
    • 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
    • setDarkmodeColor

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

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

      public WDynamicLabel 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 WDynamicLabel 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
    • setText

      public WDynamicLabel setText(Supplier<String> text)
      Sets the text of this label.
      Parameters:
      text - the new text
      Returns:
      this label
    • getAlignment

      public HorizontalAlignment getAlignment()
      Gets the horizontal text alignment of this label.
      Returns:
      the alignment
      Since:
      11.1.0
    • setAlignment

      public WDynamicLabel setAlignment(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:
      11.1.0
    • setVerticalAlignment

      public WDynamicLabel setVerticalAlignment(VerticalAlignment align)
      Sets the vertical text alignment of this label.
      Parameters:
      align - the new text alignment
      Returns:
      this label
      Since:
      11.1.0