ContextMenu class

ContextMenu

The ContextMenu class manages right-click context menus for widgets in DynamicHUD, displaying customizable options (e.g., toggles, sliders). It supports animations, skins, and integration with ContextMenuScreen for separate rendering, handling input via the Input interface.

Key Properties

  • properties: ContextMenuProperties for styling (background, border, animations).

  • options: List of Option<?> for menu items.

  • screenFactory: ContextMenuScreenFactory to create rendering screens.

  • x, y: Menu position, offset by properties.getHeightOffset().

  • scale: Animation scale (0 to 1) for open/close effects.

Key Methods

  • addOption(Option<?> option): Adds a menu option.

  • render(DrawContext, int, int, int, int): Renders the menu using the skin, applying scaling.

  • open(), close(), toggleDisplay(): Controls menu visibility.

  • createSubMenu(int, int, ContextMenuProperties): Creates nested submenus.

  • mouseClicked(double, double, int): Handles option and skin interactions.

Usage

Create a menu in AbstractMoveableScreen or widget logic typically triggered by right-click (GLFW_MOUSE_BUTTON_RIGHT) on a WidgetBox.

Then implement the ContextMenuProvider interface and return the created menu at getContextMenu() After that register via ContextMenuManager.

Example:

Last updated

Was this helpful?