Creating a custom skin
Creating a Custom Skin
This section guides you through creating a custom Skin to define a unique context menu appearance.
Steps
Extend
Skin:Create a new class extending
Skin.Optionally implement
GroupableSkinfor option group support.
Register Renderers:
In the constructor, use
addRendererto registerSkinRendererinstances for supported option types.
Implement
renderContextMenu:Draw the menu’s background and layout.
Iterate over
getOptionsto render each option using its renderer.
Handle Input:
Override input methods (
mouseClicked, etc.) for menu-level interactions.Delegate option-specific input to renderers.
Set Screen Behavior:
Use
setCreateNewScreento determine if the menu opens in a new screen.
Example:
Common Pitfalls
Not Setting Dimensions: Failing to update
contextMenu.setWidthandcontextMenu.setHeightcan cause clipping.Fix: Calculate and set dimensions based on rendered options.
Ignoring Group Support: If
supportsGroups()is false, groups are flattened, which may break hierarchical menus.Fix: Implement
GroupableSkinif groups are needed.
Test your skin with all supported option types to ensure renderers are correctly registered.
Last updated
Was this helpful?