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

Was this helpful?

  1. Widget

Widget class

This page explains the abstract Widget class..

PreviousRegistering Custom WidgetsNextHow to create a custom widget

Last updated 7 months ago

Was this helpful?

The Widget class is an abstract class that serves as a base for creating various types of widgets. It contains essential properties and methods for managing widget behavior and state.

Key Properties

  • UID: Each widget has a unique identifier (uid) for loading and saving.

  • Display: A boolean indicating whether the widget should be displayed (display).

  • Draggable: A boolean indicating whether the widget can be dragged (isDraggable).

  • Position: The widget’s position on the screen is defined by x and y coordinates.

  • Scaling: A boolean indicating whether the widget should scale with the screen (shouldScale).

*ModID* are an essential part of DynamicHUD. Each widget displayed is categorized into groups of "mod ids". This facilitates multi-Mod experience and becomes easier for DynamicHUD as well as users to segregate and identify widgets. Moreover, the secondary class uses this data to manage different widgets.

The ModID serves as a unique identifier for widgets, allowing them to be grouped under a single ID. This is particularly useful for distinguishing widgets from different mods or groups.

While it's not mandatory for the ModID to match the mod's ID, it is advisable when all widgets are associated with a single mod.

The ModID can be any chosen string.

Additionally, using ModIDs enables the creation of HUD "addons" for other mods, which can be organized under the original mod's identifier, provided that the original mod supports DynamicHUD and utilizes its ModID for identification.

Key Methods

  • displayBg: Renders a background for the widget, with a different color depending on whether it is enabled or disabled.

  • readFromTag: Reads the widget’s state from an NBT tag.

  • writeToTag: Writes the widget’s state to an NBT tag.

  • shouldDisplay: Returns whether the widget should be displayed.

  • getWidgetBox: Returns the widget’s bounding box.

WidgetBuilder Class

The WidgetBuilder is an abstract nested class used to construct widget instances. It provides methods to set properties such as position, visibility, and scaling.

This is how the builder is normally used:

MyWidget widget = new MyWidget.Builder()
        .setX(300)
        .setY(60)
        .setText("MyText")
        .setDisplay(true) // To display or not
        .shouldScale(true) // To scale or not
        .setModID(MyMod.MOD_ID)
        .build();

WidgetRenderer