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

  1. Extend Skin:

    • Create a new class extending Skin.

    • Optionally implement GroupableSkin for option group support.

  2. Register Renderers:

    • In the constructor, use addRenderer to register SkinRenderer instances for supported option types.

  3. Implement renderContextMenu:

    • Draw the menu’s background and layout.

    • Iterate over getOptions to render each option using its renderer.

  4. Handle Input:

    • Override input methods (mouseClicked, etc.) for menu-level interactions.

    • Delegate option-specific input to renderers.

  5. Set Screen Behavior:

    • Use setCreateNewScreen to determine if the menu opens in a new screen.

Example:

Common Pitfalls

  • Not Setting Dimensions: Failing to update contextMenu.setWidth and contextMenu.setHeight can 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 GroupableSkin if groups are needed.

You MUST use getOptions(contextMenu) so you avoid problems with setting groups

Last updated

Was this helpful?