Class WButton

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

public class WButton extends WWidget
  • Field Details

    • color

      protected int color
    • iconSize

      protected int iconSize
      The size (width/height) of this button's icon in pixels.
      Since:
      6.4.0
    • alignment

      protected HorizontalAlignment alignment
  • Constructor Details

    • WButton

      public WButton()
      Constructs a button with no label and no icon.
    • WButton

      public WButton(@Nullable @Nullable Icon icon)
      Constructs a button with an icon.
      Parameters:
      icon - the icon
      Since:
      2.2.0
    • WButton

      public WButton(@Nullable @Nullable Text label)
      Constructs a button with a label.
      Parameters:
      label - the label
    • WButton

      public WButton(@Nullable @Nullable Icon icon, @Nullable @Nullable Text label)
      Constructs a button with an icon and a label.
      Parameters:
      icon - the icon
      label - the label
      Since:
      2.2.0
  • Method Details

    • 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
    • canFocus

      public boolean canFocus()
      Description copied from class: WWidget
      Tests whether this widget can have the focus in the GUI.
      Overrides:
      canFocus in class WWidget
      Returns:
      true if this widget can be focused, 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
    • 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.
    • onKeyPressed

      @Environment(CLIENT) public InputResult onKeyPressed(int ch, int key, int modifiers)
      Description copied from class: WWidget
      Notifies this widget that a key has been pressed.
      Overrides:
      onKeyPressed in class WWidget
      Parameters:
      key - the GLFW scancode of the key
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • getOnClick

      @Nullable public @Nullable Runnable getOnClick()
      Gets the click handler of this button.
      Returns:
      the click handler
      Since:
      2.2.0
    • setOnClick

      public WButton setOnClick(@Nullable @Nullable Runnable onClick)
      Sets the click handler of this button.
      Parameters:
      onClick - the new click handler
      Returns:
      this button
    • isEnabled

      public boolean isEnabled()
    • setEnabled

      public WButton setEnabled(boolean enabled)
    • getLabel

      @Nullable public @Nullable Text getLabel()
    • setLabel

      public WButton setLabel(Text label)
    • getAlignment

      public HorizontalAlignment getAlignment()
    • setAlignment

      public WButton setAlignment(HorizontalAlignment alignment)
    • getIconSize

      public int getIconSize()
      Gets the current height / width of the icon.
      Returns:
      the current height / width of the icon
      Since:
      6.4.0
    • setIconSize

      public WButton setIconSize(int iconSize)
      Sets the new size of the icon.
      Parameters:
      iconSize - the new height and width of the icon
      Returns:
      this button
      Since:
      6.4.0
    • getIcon

      @Nullable public @Nullable Icon getIcon()
      Gets the icon of this button.
      Returns:
      the icon
      Since:
      2.2.0
    • setIcon

      public WButton setIcon(@Nullable @Nullable Icon icon)
      Sets the icon of this button.
      Parameters:
      icon - the new icon
      Returns:
      this button
      Since:
      2.2.0
    • 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