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
  • Overview
  • Features
  • Constructor
  • Methods
  • Properties
  • Usage Example

Was this helpful?

  1. ContextMenu

ContextMenu class

Overview

The ContextMenu class is a component of the DynamicHUD that provides a customizable context menu. It allows for the dynamic addition of options and handles its own rendering and display state. This menu is to be used for widgets and their customisation.

Features

  • Dynamic Options: Supports adding options dynamically to the context menu.

  • Customizable Appearance: Allows setting background color, padding, and other visual properties.

  • Visibility Control: Provides methods to show, hide, or toggle the display of the context menu.

  • Animation: Implements a simple scaling animation when the menu is opened.

Constructor

ContextMenu(int x, int y)

Initializes a new ContextMenu at the specified x and y coordinates, offset by the height of the widget.

Methods

addOption(Option<?> option)

Adds a new option to the context menu.

render(DrawContext drawContext, int x, int y, int height)

Renders the context menu at the specified coordinates with the given height, applying scaling and positioning based on the current state.

update()

Updates the scale for the opening animation of the context menu.

close()

Hides the context menu and resets the scale.

open()

Shows the context menu and starts the opening animation.

toggleDisplay()

Toggles the visibility of the context menu.

Properties

  • x, y: The current x and y coordinates of the context menu.

  • width, height: The current width and height of the context menu.

  • backgroundColor: The background color of the context menu.

  • padding: The padding around the context menu options.

  • heightOffset: The vertical offset from the widget to the context menu.

  • shouldDisplay: A flag indicating whether the context menu should be displayed.

  • scale: The current scale factor for the opening animation.

Usage Example

ContextMenu menu = new ContextMenu(100, 200);
menu.addOption(new Option<>("Option 1", () -> {}));
menu.open();
PreviousAbstractMoveableScreenNextUsing context menu

Last updated 1 year ago

Was this helpful?