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
  • SubMenuOption Class
  • General Summary
  • Constructor Parameters
  • Interactivity
  • Rendering
  • Example Usage

Was this helpful?

  1. ContextMenu
  2. Option<T> class

SubMenu Option

SubMenuOption Class

General Summary

SubMenuOption integrates a sub-menu alongside a toggleable button, enhancing the DynamicHUD with nested menu functionality.

Constructor Parameters

SubMenu Option offers 2 constructors like BooleanOption and RunnableOption.

  • name: The display name for the sub-menu option.

  • parentMenu: The parent ContextMenu to which this sub-menu belongs.

  • getter: Supplier that determines if the sub-menu is displayed by default.

  • setter: Consumer that updates the visibility state of the sub-menu.

The SubMenu just like BooleanOption and RunnableOption also supports BooleanPool in its second constructor where you dont have to put the getter and setter.

These are the two constructors

SubMenuOption.java
public SubMenuOption(String name, ContextMenu parentMenu, Supplier<Boolean> getter, Consumer<Boolean> setter) {
    super(getter, setter);
    Objects.requireNonNull(parentMenu, "Parent Menu cannot be null");
    this.name = name;
    this.parentMenu = parentMenu;
    this.subMenu = new ContextMenu(parentMenu.x + parentMenu.finalWidth, this.y);
    this.subMenu.heightOffset = 0;
    this.subMenu.shouldDisplay = get();
}
public SubMenuOption(String name, ContextMenu parentMenu) {
    this(name, parentMenu, () -> BooleanPool.get(name), value -> BooleanPool.put(name, value));
}

Interactivity

  • Click: Toggles the visibility of the sub-menu and updates its state.

  • Render: Shows the option's name and renders the sub-menu adjacent to the parent menu.

Rendering

  • Color Coding: The option's text color changes based on its state (green for visible, red for hidden).

  • Sub-Menu Positioning: The sub-menu is positioned beside the parent menu, aligned with the selected option.

Example Usage

ContextMenu mainMenu = new ContextMenu(100, 100);
SubMenuOption settingsOption = new SubMenuOption(
    "Settings",
    mainMenu,
    () -> userPreferences.isSettingsMenuVisible(), // Getter
    visible -> userPreferences.setSettingsMenuVisible(visible) // Setter
);

// Populate the sub-menu with options
settingsOption.getSubMenu().addOption(/* ... */);
PreviousList Option

Last updated 9 months ago

Was this helpful?