> 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/contextmenu/using-context-menu.md).

# Using context menu

Context menus are usually created inside the widget class itself and opened on right-click.

The recommended setup is:

* Create the menu with [ContextMenuProperties](/dynamic-hud/contextmenu/contextmenuproperties.md).
* Add your options.
* Implement [ContextMenuProvider](/dynamic-hud/contextmenu/contextmenuprovider.md).
* Register the widget in [ContextMenuManager](/dynamic-hud/contextmenu/contextmenumanager.md).
* Open the menu from `mouseClicked`.

Example:

```java
public class MyWidget extends Widget implements ContextMenuProvider {
    private ContextMenu<?> menu;
    private boolean shadow = true;
    private String alignment = "Left";
    private final List<String> alignments = Arrays.asList("Left", "Center", "Right");
    
    public MyWidget(String modId) {
        super(DATA, modId);
        createMenu();
        ContextMenuManager.getInstance().registerProvider(this);
    }

    public void createMenu() {
        ContextMenuProperties properties = ContextMenuProperties.builder().build();
        menu = new ContextMenu<>(getX(), getY(), properties);

        menu.addOption(new BooleanOption("Shadow", () -> this.shadow, value -> this.shadow = value));
        menu.addOption(new CycleOption<>("Alignment", () -> this.alignment, value -> this.alignment = value, alignments));
    }

    @Override
    public ContextMenu<?> getContextMenu() {
        return menu;
    }

    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        menu.toggleDisplay(widgetBox, mouseX, mouseY, button);
        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public void onClose() {
        super.onClose();
        menu.close();
    }
}
```

{% hint style="info" %}
Use `CycleOption` for values that need forward and backward cycling.
{% endhint %}
