# GradientSlider

## GradientSlider

The [`GradientSlider`](https://github.com/V-Fast/DynamicHUD/blob/master/src/main/java/com/tanishisherewith/dynamichud/util/colorpicker/GradientSlider.java) class provides functionality for creating and displaying gradient sliders in Minecraft Fabric.

### Fields

* `width`: The width of the gradient slider.
* `height`: The height of the gradient slider.
* `selectedWidget`: The widget that this gradient slider is associated with.
* `x`: The x position of the gradient slider.
* `y`: The y position of the gradient slider.
* `hue`: The hue of the gradient slider.
* `isDragging`: Whether the handle of the gradient slider is currently being dragged.

### Constructors

#### GradientSlider(int x, int y, int width, int height, Widget selectedWidget)

Constructs a `GradientSlider` object with the given position, size, and selected widget.

### Methods

#### tick()

Updates the progress and alpha of the gradient slider.

#### render(MatrixStack matrices)

Renders this gradient slider on screen.

#### setPosition(int x, int y)

Sets the position of this gradient slider.

#### onClick(double mouseX, double mouseY, int button)

Handles mouse clicks on this gradient slider. This method sets the dragging state to true if the mouse is over the handle and the left mouse button was clicked. It also updates the hue of the gradient slider based on the mouse position if the mouse is over the gradient slider.

#### isMouseOver(double mouseX, double mouseY)

Returns whether the mouse is currently over this gradient slider.

#### onRelease(double mouseX, double mouseY, int button)

Handles mouse release events on this gradient slider. This method stops dragging or scaling the handle.

#### onDrag(double mouseX, double mouseY, int button)

Handles mouse dragging on this gradient slider. This method updates the hue of the gradient slider based on the mouse position if the handle is being dragged.

#### getHue()

Returns the current hue of this gradient slider.

#### setHue(float hue)

Sets the hue of this gradient slider.

The GradientSlider is already called and present in [ColorGradientPicker](/archived-legacy-dynamichud/colorpicker/colorgradientpicker.md). But if you still want to add it yourself somewhere you can do it by:Here's an example of how to use a `GradientSlider` in your Minecraft Fabric mod:

```java
// Create a new GradientSlider
GradientSlider slider = new GradientSlider(10, 10, 100, 20);

// Render the GradientSlider
slider.render(matrices);

// Handle mouse input
if (slider.onClick(mouseX, mouseY)) {
    // The mouse was clicked on the slider
}
if (slider.onDrag(mouseX, mouseY)) {
    // The mouse was dragged on the slider
}
if (slider.onRelease(mouseX, mouseY)) {
    // The mouse was released on the slider
}

// Get and set values for the GradientSlider
float hue = slider.getHue();
slider.setHue(0.5f);
```

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

Finally, we get and set values for hue using its getter and setter methods.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tanishisherewith.gitbook.io/archived-legacy-dynamichud/colorpicker/colorgradientpicker/gradientslider.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
