|
Window Framework v1.2.4
Window Framework for Unity UI Toolkit
|
A mouse manipulator that enables drag-and-move functionality for WindowFrame elements in Unity's UI Toolkit. More...
Public Member Functions | |
| WindowFrameDragger () | |
| Initializes a new instance of the WindowFrameDragger with left-click activation. | |
Protected Member Functions | |
| override void | RegisterCallbacksOnTarget () |
| Registers mouse event callbacks on the target element. | |
| override void | UnregisterCallbacksFromTarget () |
| Unregisters mouse event callbacks from the target element. | |
Private Member Functions | |
| Vector2 | GetClampedWindowLocation (float rootX, float rootY, VisualElement _targetWindow) |
| Calculates and enforces position constraints for window movement operations. | |
| void | OnMouseDown (MouseDownEvent e) |
| Handles mouse down events to initiate window dragging operations. | |
| void | OnMouseMove (MouseMoveEvent e) |
| Handles mouse move events to update window position during drag operations. | |
| void | OnMouseUp (MouseUpEvent e) |
| Handles mouse up events to complete window dragging operations. | |
Private Attributes | |
| float | _clickXOffset |
| The horizontal offset between the mouse click position and the window's left edge. | |
| float | _clickYOffset |
| The vertical offset between the mouse click position and the window's top edge. | |
| bool | _isActive |
| Indicates whether a drag operation is currently active. | |
This manipulator allows users to click and drag windows to reposition them within the screen boundaries. It respects window locking states and movement permissions while ensuring windows remain visible on screen. The dragger integrates seamlessly with the WindowFrame system to provide smooth, constrained window movement.
Key Features:
| GWG.WindowFramework.Manipulators.WindowFrameDragger.WindowFrameDragger | ( | ) |
The constructor configures the manipulator to respond only to left mouse button interactions. This prevents conflicts with other mouse operations such as context menus (right-click) or specialized middle-click behaviors.
The manipulator starts in an inactive state and will only begin drag operations when proper mouse down events are received on elements that allow movement.
|
private |
| rootX | The requested X position of the mouse cursor |
| rootY | The requested Y position of the mouse cursor |
| _targetWindow | The VisualElement being moved (typically a WindowFrame) |
This method implements comprehensive position constraint logic to ensure windows remain visible and usable within the screen boundaries:
Position Calculation:
Boundary Enforcement:
The constraints ensure that windows remain fully accessible and cannot be accidentally moved off-screen where they would become difficult to retrieve.
|
private |
| e | The mouse down event data containing click position and button information |
This method performs comprehensive validation and setup for drag operations:
Validation Steps:
Setup Operations:
The method will exit early if any validation fails, ensuring that locked or movement-disabled windows cannot be dragged.
|
private |
| e | The mouse move event data containing current cursor position |
This method continuously updates the window position while a drag operation is active:
The position calculation uses the stored click offsets to maintain the relative position between the cursor and the window, providing smooth and predictable movement behavior throughout the drag operation.
|
private |
| e | The mouse up event data |
This method finalizes the drag operation when the user releases the mouse button:
After this method completes, the window remains in its new position and normal mouse interaction is fully restored. The drag operation is complete and the window can be interacted with normally or dragged again.
|
protected |
This method is automatically called by the UI Toolkit when the manipulator is added to a target element. It establishes the event handling chain for:
The callbacks are registered to handle events in the appropriate phase to ensure reliable drag behavior even with complex UI hierarchies.
|
protected |
This method is automatically called by the UI Toolkit when the manipulator is removed from an element or when the element is destroyed. It ensures proper cleanup of event handlers to prevent memory leaks.
Unregistration is essential for maintaining application performance and preventing orphaned event handlers from consuming resources or causing unexpected behavior after elements are no longer active.
|
private |
This offset is calculated when a drag operation begins and maintains the relative position between the cursor and window origin throughout the drag operation. This ensures smooth, predictable movement regardless of where on the draggable element the user initially clicks.
|
private |
This offset is calculated when a drag operation begins and maintains the relative position between the cursor and window origin throughout the drag operation. This ensures smooth, predictable movement regardless of where on the draggable element the user initially clicks.
|
private |
Set to true when a valid drag operation begins and false when it ends. Used to control event processing and ensure drag operations are properly contained within mouse down/up pairs.