> 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/widget-renderer.md).

# Widget Renderer

The `WidgetRenderer` class is a key component in rendering widgets on the screen for your Minecraft mod. This class manages the list of widgets and controls their rendering based on the current screen and user interactions.

{% hint style="info" %}
The Widget Renderer class is designed to segregate widget rendering by groups.&#x20;

The AbstractMoveableScreen utilizes the WidgetRenderer to display and drag widgets from a single group, unlike earlier versions which allowed dragging widgets from all mods within a single screen. This makes it easier for mod developers as well as players to manage widgets.
{% endhint %}

### Class Variables

* `List<Class<? extends Screen>> allowedScreens`: A thread-safe list that holds the classes of screens where widgets are allowed to be rendered.
* `boolean isInEditor`: A flag indicating whether the widget is in editor mode.
* `Widget selectedWidget`: The currently selected widget.
* `List<Widget> widgets`: The list of widgets that this renderer should render.
* `boolean renderInGameHud`: A flag indicating whether widgets should be rendered in the in-game HUD.

### Constructor

The constructor takes a list of widgets that the renderer should render.

```java
public WidgetRenderer(List<Widget> widgets) {
    this.widgets = widgets;
    addScreen(GameMenuScreen.class);
}
```

### Methods

* `void addWidget(Widget widget)`: Adds a widget to the list of widgets to be rendered.
* `void addScreen(Class<? extends Screen> screen)`: Adds a screen class to the list of allowed screens where widgets can be rendered.
* `void shouldRenderInGameHud(boolean renderInGameHud)`: Sets whether widgets should be rendered in the in-game HUD.
* `void renderWidgets(DrawContext context, int mouseX, int mouseY)`: Renders the widgets based on the current screen and whether the widget is in editor mode.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://tanishisherewith.gitbook.io/dynamic-hud/widget/widget-renderer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
