Class WToggleButton

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

public class WToggleButton extends WWidget
  • Field Details

    • DEFAULT_OFF_IMAGE

      protected static final Texture DEFAULT_OFF_IMAGE
    • DEFAULT_ON_IMAGE

      protected static final Texture DEFAULT_ON_IMAGE
    • DEFAULT_FOCUS_IMAGE

      protected static final Texture DEFAULT_FOCUS_IMAGE
    • onImage

      protected Texture onImage
    • offImage

      protected Texture offImage
    • focusImage

      protected Texture focusImage
    • label

      @Nullable protected @Nullable Text label
    • isOn

      protected boolean isOn
    • onToggle

      @Nullable protected @Nullable Consumer<Boolean> onToggle
    • color

      protected int color
    • darkmodeColor

      protected int darkmodeColor
  • Constructor Details

    • WToggleButton

      public WToggleButton()
      Constructs a toggle button with default images and no label.
    • WToggleButton

      public WToggleButton(Text label)
      Constructs a toggle button with default images.
      Parameters:
      label - the button label
    • WToggleButton

      public WToggleButton(Identifier onImage, Identifier offImage)
      Constructs a toggle button with custom images and no label.
      Parameters:
      onImage - the toggled on image
      offImage - the toggled off image
    • WToggleButton

      public WToggleButton(Identifier onImage, Identifier offImage, Text label)
      Constructs a toggle button with custom images.
      Parameters:
      onImage - the toggled on image
      offImage - the toggled off image
      label - the button label
    • WToggleButton

      public WToggleButton(Texture onImage, Texture offImage)
      Constructs a toggle button with custom images and no label.
      Parameters:
      onImage - the toggled on image
      offImage - the toggled off image
      Since:
      3.0.0
    • WToggleButton

      public WToggleButton(Texture onImage, Texture offImage, Text label)
      Constructs a toggle button with custom images.
      Parameters:
      onImage - the toggled on image
      offImage - the toggled off image
      label - the button label
      Since:
      3.0.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
    • 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
    • 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

      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.
    • onToggle

      protected void onToggle(boolean on)
    • getToggle

      public boolean getToggle()
    • setToggle

      public void setToggle(boolean on)
    • getOnToggle

      @Nullable public @Nullable Consumer<Boolean> getOnToggle()
    • setOnToggle

      public WToggleButton setOnToggle(@Nullable @Nullable Consumer<Boolean> onToggle)
    • getLabel

      @Nullable public @Nullable Text getLabel()
    • setLabel

      public WToggleButton setLabel(@Nullable @Nullable Text label)
    • setColor

      public WToggleButton setColor(int light, int dark)
    • getOnImage

      public Texture getOnImage()
    • setOnImage

      public WToggleButton setOnImage(Texture onImage)
    • getOffImage

      public Texture getOffImage()
    • setOffImage

      public WToggleButton setOffImage(Texture offImage)
    • getFocusImage

      public Texture getFocusImage()
    • setFocusImage

      public WToggleButton setFocusImage(Texture focusImage)
    • 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