|
Window Framework v1.2.4
Window Framework for Unity UI Toolkit
|
A mouse manipulator that enables context menu functionality for any VisualElement in Unity's UI Toolkit. More...
Public Member Functions | |
| ContextMenuActivator (ContextMenuConfig contextMenuConfig, int clickCount=1, MouseButton button=MouseButton.RightMouse) | |
| Initializes a new ContextMenuActivator with the specified configuration and activation settings. | |
| void | ShowContextMenu (Vector2 mousePosition) |
| Displays the context menu at the specified position using the configured menu structure. | |
Protected Member Functions | |
| override void | RegisterCallbacksOnTarget () |
| Registers event callbacks on the target element to handle context menu activation. | |
| override void | UnregisterCallbacksFromTarget () |
| Unregisters event callbacks from the target element during cleanup. | |
Private Member Functions | |
| void | OnMouseDown (MouseDownEvent evt) |
| Handles mouse down events to activate the context menu when conditions are met. | |
Private Attributes | |
| ContextMenuConfig | contextMenuConfig |
| The configuration object defining the context menu structure, items, and actions. | |
This manipulator provides flexible context menu activation with customizable trigger conditions. It integrates seamlessly with the Window Framework's context menu system and tooltip management.
Key Features:
Default Behavior:
The manipulator requires a ContextMenuConfig object that defines the menu structure, items, and associated actions. This configuration-based approach allows for flexible menu customization without modifying the activation logic.
| GWG.WindowFramework.Manipulators.ContextMenuActivator.ContextMenuActivator | ( | ContextMenuConfig | contextMenuConfig, |
| int | clickCount = 1, | ||
| MouseButton | button = MouseButton::RightMouse ) |
| contextMenuConfig | The configuration object defining the context menu structure and actions |
| clickCount | The number of clicks required to activate the context menu. Default: 1 |
| button | The mouse button that triggers the context menu. Default: MouseButton.RightMouse |
The constructor configures the manipulator's activation filter based on the provided parameters. This allows for flexible context menu activation patterns to suit different UI design requirements.
Common Activation Patterns:
The contextMenuConfig parameter is required and must contain properly configured menu items and actions. The configuration is validated when the menu is displayed.
|
private |
| evt | The mouse down event data containing button information and cursor position |
This method processes mouse down events and determines whether to activate the context menu based on the configured activation criteria:
Validation Process:
Activation Process:
The method integrates with the Window Framework's tooltip system to ensure clean UI behavior by hiding tooltips before showing context menus.
|
protected |
This method establishes the event handling infrastructure for context menu activation by registering callbacks for two primary activation methods:
Mouse Activation:
Keyboard Activation:
The TrickleDown registration ensures that the context menu activation is processed before other elements can intercept the mouse events, providing reliable activation behavior in complex UI hierarchies.
| void GWG.WindowFramework.Manipulators.ContextMenuActivator.ShowContextMenu | ( | Vector2 | mousePosition | ) |
| mousePosition | The screen position where the context menu should appear |
This method creates and displays a context menu using the Window Framework's context menu system. It handles the complete menu lifecycle from creation to cleanup:
Menu Creation:
Display Configuration:
The method includes a callback mechanism that is triggered when the menu closes, allowing for post-menu cleanup or state updates if needed.
|
protected |
This method performs cleanup by removing the event callbacks that were registered during initialization. It ensures proper resource management and prevents memory leaks when the manipulator is removed or the element is destroyed.
The method attempts to unregister both mouse and navigation event callbacks to maintain cleanup symmetry with the registration process. Debug logging is included to assist with troubleshooting callback lifecycle issues.
Note: The NavigationSubmitEvent unregistration uses an empty lambda as Unity's UI Toolkit requires the exact same callback delegate reference for proper unregistration. In practice, this specific pattern may need refinement for complete cleanup.
|
private |
This configuration contains all the information needed to build and display the context menu, including:
The configuration is provided during construction and used whenever the context menu needs to be displayed.