SubMenu Option

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.

circle-info

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

Last updated