ColorPickerButton

This page talks about ColorPickerButton class

ColorPickerButton

The ColorPickerButton class provides functionality for creating and displaying color picker buttons in Minecraft Fabric.

Fields

  • x: The x position of the button.

  • y: The y position of the button.

  • width: The width of the button.

  • height: The height of the button.

  • isPicking: Whether the button is currently in picking mode.

Constructors

ColorPickerButton(int x, int y, int width, int height)

Constructs a ColorPickerButton object with the given position and size.

Methods

render(MatrixStack matrices)

Renders this button on screen.

onClick(double mouseX, double mouseY, int button)

Handles mouse clicks on this button. This method sets the picking mode to true if the mouse is over the button and the left mouse button was clicked.

isPicking()

Returns whether this button is currently in picking mode.

setPicking(boolean picking)

Sets whether this button is currently in picking mode.

The ColorPickerButton is already called and present in ColorGradientPicker. But if you still want to add it yourself somewhere you can do it by:

// Create a new ColorPickerButton
ColorPickerButton button = new ColorPickerButton(10, 10, 100, 20);

// Render the ColorPickerButton
button.render(matrices);

// Handle mouse input
if (button.onClick(mouseX, mouseY)) {
    // The mouse was clicked on the button
}

In this example, we create a new ColorPickerButton with a position of (10, 10) and a size of (100, 20). We then render the ColorPickerButton on screen using its render method. We also handle mouse input by calling its onClick method.