> For the complete documentation index, see [llms.txt](https://tanishisherewith.gitbook.io/dynamic-hud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tanishisherewith.gitbook.io/dynamic-hud/widget/widgetdata.md).

# WidgetData

The `WidgetData` class is a Java record that encapsulates the data needed to create a widget. It uses Java’s `Supplier` functional interface to provide a factory method for creating widgets.

> This class is mostly used for loading widgets. This provides an automatic way of producing widget (also known as widgetFactory).

### Key Components

* **name**: A `String` that represents the name of the widget.
* **description**: A `String` that provides a description of the widget.
* **widgetFactory**: A `Supplier<T>` where `T` extends `Widget`. This is a factory method for creating instances of the widget.

### Methods

* **name()**: This method returns the name of the widget.
* **description()**: This method returns the description of the widget.
* **createWidget()**: This method uses the `widgetFactory` to create a new instance of the widget.

### Usage

Here’s an example of how you might use the `WidgetData` class:

```java
WidgetData<MyWidget> myWidgetData = new WidgetData<>(
    "MyWidget", // Name of the widget
    "This is my custom widget.", // Description of the widget
    () -> new MyWidget() // Factory method for creating the widget
);

// Create a new instance of MyWidget (Used in WidgetManager to load from a save file)
Widget myWidget = myWidgetData.createWidget();
```

{% hint style="success" %}
Create an empty constructor in your Widget class providing garbage values to your instance variables, as they will be overwritten by saved data before any of the Widgets interact with the game, thus ensuring safety.
{% endhint %}
