DynamicHUD Dev Guide
DownloadNeed Support?
  • Dynamic HUD
  • Import using Gradle
  • Integrating DynamicHUD
    • Integrating DynamicHUD
    • Adding Widgets
    • Adding your own WidgetRenderer
    • Passing AbstractMoveableScreen instance
    • Changing default key bind
    • Changing save and load file
    • Registering Custom Widgets
  • Widget
    • Widget class
    • How to create a custom widget
    • Widget Renderer
    • WidgetData
    • DynamicValueRegistry
    • Scaling
  • Screens
    • AbstractMoveableScreen
  • ContextMenu
    • ContextMenu class
    • Using context menu
    • Option<T> class
      • Color Option
      • Boolean Option
      • Double Option
      • Runnable Option
      • Enum Option
      • List Option
      • SubMenu Option
Powered by GitBook
On this page
  • Key Components
  • Methods
  • Usage

Was this helpful?

  1. Widget

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:

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
Widget myWidget = myWidgetData.createWidget();
PreviousWidget RendererNextDynamicValueRegistry

Last updated 4 months ago

Was this helpful?