|
Window Framework v1.2.4
Window Framework for Unity UI Toolkit
|
A sophisticated context menu implementation for the Window Framework that provides dynamic menu creation with fade animations and intelligent positioning. More...
Public Member Functions | |
| void | Show (Vector2 mousePosition, ContextMenuConfig config, VisualElement target, Action onClose, bool selfAdd=true) |
| Displays the context menu at the specified position with the given configuration and event handlers. | |
Private Member Functions | |
| VisualElement | AddMenuItem (string text, bool isChecked, bool isDisabled, Action action=null) |
| Creates a menu item element with the specified properties and behavior. | |
| void | FadeAndRemove () |
| Initiates the fade-out animation sequence and schedules menu removal. | |
| void | RemoveNow () |
| Immediately removes the context menu from the visual hierarchy and performs complete cleanup. | |
| void | SetDisabledForFade () |
| Disables all menu items to prevent interaction during the fade-out animation. | |
Private Attributes | |
| float | _delay |
| The delay in seconds before the fade-out animation begins after the mouse leaves the menu area. | |
| float | _fadeTime |
| The duration in seconds for the fade-out animation effect. | |
| IVisualElementScheduledItem | _task |
| Reference to the scheduled task managing fade-out animation and menu removal. | |
WindowFrameContextMenu is a specialized VisualElement that creates contextual menus with advanced features:
Key Features:
Menu Structure: The context menu consists of a wrapper container that holds:
Animation System:
Event Handling: The menu responds to various events for natural user interaction:
Integration: Works seamlessly with ContextMenuConfig objects and ContextMenuActivator manipulators to provide a complete context menu system.
|
private |
| text | The display text for the menu item |
| isChecked | Whether to display a checkmark next to the item |
| isDisabled | Whether the item should appear disabled and non-interactive |
| action | The action to execute when the item is clicked (null for disabled items) |
This method creates a structured menu item with the following components:
Item Structure:
Visual States:
Event Handling:
CSS Classes:
The method provides a consistent visual structure while allowing flexible content and behavior through the configuration parameters.
|
private |
This method manages the graceful dismissal of the context menu through a two-stage process:
Stage 1 - Delay Phase:
Stage 2 - Fade Phase:
Animation Details:
The method ensures that users have adequate time to re-engage with the menu while providing smooth visual feedback when dismissal is inevitable.
|
private |
This method provides instant menu dismissal with comprehensive cleanup operations:
Animation Cleanup:
Event Cleanup:
Hierarchy Management:
Window Management Integration:
This method is used for immediate dismissal scenarios such as menu item clicks, Escape key presses, or outside clicks where fade animations would be inappropriate.
|
private |
This method ensures that users cannot accidentally trigger menu actions while the menu is fading out, preventing unintended operations and maintaining clean visual feedback:
Disabling Process:
Visual Effect:
Scope:
This ensures a professional fade-out experience where visual feedback clearly indicates that the menu is no longer interactive.
| void GWG.WindowFramework.WindowFrameContextMenu.Show | ( | Vector2 | mousePosition, |
| ContextMenuConfig | config, | ||
| VisualElement | target, | ||
| Action | onClose, | ||
| bool | selfAdd = true ) |
| mousePosition | The screen coordinates where the context menu should appear |
| config | Configuration object containing menu structure, items, and behaviors |
| target | The VisualElement that triggered the context menu display |
| onClose | Callback function executed when the menu is dismissed |
| selfAdd | If true, automatically adds the menu to the WindowFrameController's root element |
This method orchestrates the complete context menu display process with sophisticated positioning and configuration logic:
Container Management:
Event Registration:
Menu Structure Creation:
Theming and Positioning:
The method provides intelligent defaults while allowing full customization through the configuration object and callback parameters.
|
private |
This value is retrieved from WindowFrameController.ContextMenuFadeDelay during menu display and provides users time to return their cursor to the menu before it starts fading away. This prevents accidental menu dismissal during cursor movements between menu items.
|
private |
This value is retrieved from WindowFrameController.ContextMenuFadeTime during menu display and cached for consistent animation behavior throughout the menu's lifecycle. A value of 0 results in instant disappearance without fade animation.
|
private |
This task handles the timing and execution of fade-out effects and final menu removal. It can be paused or canceled when immediate menu dismissal is required, such as when the user clicks a menu item or presses the Escape key.