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

public class WBar extends WWidget
A bar that displays int values from a PropertyDelegate.

Bars can be used for all kinds of bars including progress bars (and progress arrows) and energy bars.

  • Field Details

    • bg

      @Nullable protected final @Nullable Texture bg
      The background texture. If not null, it will be drawn behind the bar contents.
    • bar

      @Nullable protected final @Nullable Texture bar
      The bar texture. If not null, it will be drawn to represent the current field.
    • field

      protected final int field
      The ID of the displayed property in the properties.
    • max

      protected final int max
      The ID of the property representing the maximum value of the field.

      If max is negative, the maxValue constant will be used instead.

    • maxValue

      protected int maxValue
      The constant maximum value of the field.

      This constant will only be used if max is negative.

      See Also:
    • properties

      protected PropertyDelegate properties
      The properties used for painting this bar.

      The current value is read from the property with ID field, and the maximum value is usually read from the property with ID max.

    • direction

      protected final WBar.Direction direction
      The direction of this bar, representing where the bar will grow when the field increases.
    • tooltipLabel

      protected String tooltipLabel
      The translation key of the tooltip.
      See Also:
    • tooltipTextComponent

      protected Text tooltipTextComponent
      A tooltip text component. This can be used instead of tooltipLabel, or together with it. In that case, this component will be drawn after the other label.
  • Constructor Details

  • Method Details

    • withTooltip

      public WBar withTooltip(String label)
      Adds a tooltip to the WBar.

      Formatting Guide: The tooltip label is passed into String.format and can receive two integers (%d) - the first is the current value of the bar's focused field, and the second is the bar's focused maximum.

      Parameters:
      label - the translation key of the string to render on the tooltip
      Returns:
      this bar with tooltip enabled and set
    • withTooltip

      public WBar withTooltip(Text label)
      Adds a tooltip Text to the WBar.
      Parameters:
      label - the added tooltip label
      Returns:
      this bar
    • 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
    • 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
    • addTooltip

      @Environment(CLIENT) public void addTooltip(TooltipBuilder information)
      Description copied from class: WWidget
      Adds lines to this widget's tooltip. If the lines remain empty after this call, no tooltip will be drawn.
      Overrides:
      addTooltip in class WWidget
      Parameters:
      information - the builder to add tooltip lines to
    • validate

      public void validate(GuiDescription host)
      Description copied from class: WWidget
      Creates component peers and initializes animation data for this Widget and all its children. The host screen handler must clear any heavyweight peers from its records before this method is called.

      This method must be called on the root panel of any screen once the widgets have been initialized.

      Overrides:
      validate in class WWidget
      Parameters:
      host - the host GUI description
    • getProperties

      @Nullable public @Nullable PropertyDelegate getProperties()
      Gets the current properties of this bar.
      Returns:
      the current property delegate, or null if not initialized yet
    • setProperties

      public WBar setProperties(PropertyDelegate properties)
      Sets the current properties of this bar.

      This method is meant for situations when a GUI description is unavailable (such as HUDs). GuiDescription.getPropertyDelegate() should be preferred over this if available.

      Parameters:
      properties - the properties
      Returns:
      this bar
    • withConstantMaximum

      public static WBar withConstantMaximum(Identifier bg, Identifier bar, int field, int maxValue, WBar.Direction dir)
      Creates a WBar that has a constant maximum-value instead of getting the maximum from a field.
      Parameters:
      bg - the background image to use for the bar
      bar - the foreground image that represents the filled bar
      field - the field index for bar values
      maxValue - the constant maximum value for the bar
      dir - the direction the bar should grow towards
      Returns:
      a new WBar with a constant maximum value
    • withConstantMaximum

      public static WBar withConstantMaximum(Texture bg, Texture bar, int field, int maxValue, WBar.Direction dir)
      Creates a WBar that has a constant maximum-value instead of getting the maximum from a field.
      Parameters:
      bg - the background image to use for the bar
      bar - the foreground image that represents the filled bar
      field - the field index for bar values
      maxValue - the constant maximum value for the bar
      dir - the direction the bar should grow towards
      Returns:
      a new WBar with a constant maximum value
      Since:
      4.1.0