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
Last updated
Was this helpful?