Window Framework v1.2.4
Window Framework for Unity UI Toolkit
Loading...
Searching...
No Matches
GWG.WindowFramework.Manipulators.ClickActivatorConfigurable Class Reference

A configurable mouse manipulator that provides flexible click event handling with customizable activation criteria. More...

Inheritance diagram for GWG.WindowFramework.Manipulators.ClickActivatorConfigurable:

Public Member Functions

 ClickActivatorConfigurable (Action action=null)
 Initializes a new ClickActivatorConfigurable with default settings (single left-click).
 ClickActivatorConfigurable (int clickCount, Action action)
 Initializes a new ClickActivatorConfigurable with a specific click count and default left mouse button.
 ClickActivatorConfigurable (int clickCount, MouseButton button, Action action)
 Initializes a new ClickActivatorConfigurable with full customization of click count, mouse button, and action.

Protected Member Functions

override void RegisterCallbacksOnTarget ()
 Registers the mouse down event callback on the target element.
override void UnregisterCallbacksFromTarget ()
 Unregisters the mouse down event callback from the target element during cleanup.

Private Member Functions

void Init (int clickCount, MouseButton button, Action action)
 Performs common initialization logic for all constructor overloads.
void OnMouseDown (MouseDownEvent evt)
 Handles mouse down events and executes the configured action when activation criteria are met.

Private Attributes

Action _action
 The action delegate that will be executed when the configured click pattern is detected.

Detailed Description

This manipulator simplifies the process of creating custom click behaviors by providing a streamlined alternative to manually configuring Clickable manipulators with activation filters. It offers flexible configuration options for different click patterns and mouse buttons.

Key Features:

  • Configurable click count (single, double, triple, etc.)
  • Configurable mouse button (left, right, middle)
  • Simple action-based callback system
  • Automatic event propagation control
  • Clean initialization through multiple constructor overloads

Advantages over Manual Clickable Setup:

  • Simplified constructor-based configuration
  • Built-in activation filter management
  • Automatic event propagation handling
  • Consistent initialization patterns
  • Reduced boilerplate code

This manipulator is particularly useful for creating custom UI interactions that require specific click patterns or non-standard mouse button behaviors that go beyond basic button click handling.

// Simple left-click action
var simpleClicker = new ClickActivatorConfigurable(() => Debug.Log("Clicked!"));
myElement.AddManipulator(simpleClicker);
// Double-click action
var doubleClicker = new ClickActivatorConfigurable(2, () => Debug.Log("Double-clicked!"));
myImage.AddManipulator(doubleClicker);
// Right-click action
var rightClicker = new ClickActivatorConfigurable(1, MouseButton.RightMouse, () => ShowContextMenu());
myPanel.AddManipulator(rightClicker);
// Triple middle-click for advanced functionality
var advancedClicker = new ClickActivatorConfigurable(3, MouseButton.MiddleMouse, () => AdvancedAction());
expertPanel.AddManipulator(advancedClicker);
// Complex action with multiple operations
var complexAction = new ClickActivatorConfigurable(() => {
SaveCurrentState();
UpdateUI();
LogAction("Complex operation completed");
});
workflowButton.AddManipulator(complexAction);
// Comparison with manual Clickable setup:
// Manual approach:
var clickable = new Clickable(() => Debug.Log("Manual setup"));
clickable.activators.Add(new ManipulatorActivationFilter {
button = MouseButton.LeftMouse,
clickCount = 2
});
element.AddManipulator(clickable);
// Simplified approach with ClickActivatorConfigurable:
element.AddManipulator(new ClickActivatorConfigurable(2, () => Debug.Log("Simplified setup")));
ClickActivatorConfigurable(Action action=null)
Initializes a new ClickActivatorConfigurable with default settings (single left-click).
Definition ClickActivatorConfigurable.cs:135

Constructor & Destructor Documentation

◆ ClickActivatorConfigurable() [1/3]

GWG.WindowFramework.Manipulators.ClickActivatorConfigurable.ClickActivatorConfigurable ( Action action = null)
Parameters
actionThe action to execute when a click is detected. Can be null.

This constructor provides the simplest initialization for standard left-click behavior. It's equivalent to creating a basic Clickable but with the added benefit of consistent initialization patterns and automatic event handling.

Default Configuration:

  • Click Count: 1 (single click)
  • Mouse Button: Left mouse button
  • Action: As provided (can be null for no operation)

This constructor is ideal for simple UI interactions where standard click behavior is desired without additional complexity.

// Simple click handler
var basicClicker = new ClickActivatorConfigurable(() => Debug.Log("Element clicked"));
button.AddManipulator(basicClicker);
// Click handler with method reference
var methodClicker = new ClickActivatorConfigurable(HandleElementClick);
panel.AddManipulator(methodClicker);
// Click handler with complex logic
var complexClicker = new ClickActivatorConfigurable(() => {
if (CanPerformAction())
{
PerformAction();
UpdateState();
}
});
conditionalElement.AddManipulator(complexClicker);
// Null action (useful for event interception without action)
var interceptor = new ClickActivatorConfigurable(null);
eventBlocker.AddManipulator(interceptor);

◆ ClickActivatorConfigurable() [2/3]

GWG.WindowFramework.Manipulators.ClickActivatorConfigurable.ClickActivatorConfigurable ( int clickCount,
Action action )
Parameters
clickCountThe number of consecutive clicks required to activate the action
actionThe action to execute when the click pattern is detected

This constructor allows customization of the click count while maintaining the standard left mouse button behavior. It's particularly useful for implementing double-click, triple-click, or other multi-click interactions.

Click Count Behavior:

  • 1: Single click (immediate activation)
  • 2: Double-click (requires two rapid clicks)
  • 3+: Multiple clicks (requires specified number of rapid consecutive clicks)

The timing for multi-click detection is handled by Unity's UI Toolkit and follows system double-click timing settings. Clicks must occur within the system-defined time window to be recognized as part of the same click sequence.

// Double-click to edit
var doubleClickEditor = new ClickActivatorConfigurable(2, () => StartEditMode());
textLabel.AddManipulator(doubleClickEditor);
// Triple-click to select all
var tripleClickSelector = new ClickActivatorConfigurable(3, () => SelectAllContent());
textArea.AddManipulator(tripleClickSelector);
// Quadruple-click for easter egg
var easterEggActivator = new ClickActivatorConfigurable(4, () => ShowEasterEgg());
hiddenElement.AddManipulator(easterEggActivator);
// Different click counts for different actions on same element
var multiActionElement = new VisualElement();
multiActionElement.AddManipulator(new ClickActivatorConfigurable(1, () => ShowInfo()));
multiActionElement.AddManipulator(new ClickActivatorConfigurable(2, () => ShowDetails()));
multiActionElement.AddManipulator(new ClickActivatorConfigurable(3, () => ShowAdvanced()));

◆ ClickActivatorConfigurable() [3/3]

GWG.WindowFramework.Manipulators.ClickActivatorConfigurable.ClickActivatorConfigurable ( int clickCount,
MouseButton button,
Action action )
Parameters
clickCountThe number of consecutive clicks required to activate the action
buttonThe specific mouse button that triggers the action
actionThe action to execute when the click pattern is detected

This constructor provides complete control over click activation behavior, allowing customization of both the click pattern and the mouse button used for activation. It's the most flexible constructor and supports advanced interaction scenarios.

Mouse Button Options:

  • MouseButton.LeftMouse: Standard primary interaction button
  • MouseButton.RightMouse: Typically used for context menus or secondary actions
  • MouseButton.MiddleMouse: Often used for specialized actions like view manipulation

This constructor enables the creation of sophisticated interaction patterns that can differentiate between different mouse buttons and click frequencies, allowing for rich, context-sensitive user interfaces.

// Right-click single-click for context menu
var contextMenuActivator = new ClickActivatorConfigurable(1, MouseButton.RightMouse, () => ShowContextMenu());
dataGrid.AddManipulator(contextMenuActivator);
// Middle-click for special navigation
var middleClickNavigator = new ClickActivatorConfigurable(1, MouseButton.MiddleMouse, () => OpenInNewTab());
linkElements.AddManipulator(middleClickNavigator);
// Double right-click for advanced options
var advancedOptions = new ClickActivatorConfigurable(2, MouseButton.RightMouse, () => ShowAdvancedMenu());
expertPanel.AddManipulator(advancedOptions);
// Triple middle-click for developer tools
var devTools = new ClickActivatorConfigurable(3, MouseButton.MiddleMouse, () => {
if (Application.isEditor)
ShowDeveloperTools();
});
debugPanel.AddManipulator(devTools);
// Complex multi-button interaction system
var interactiveElement = new VisualElement();
// Primary action: Left-click
interactiveElement.AddManipulator(new ClickActivatorConfigurable(1, MouseButton.LeftMouse, PrimaryAction));
// Secondary action: Right-click
interactiveElement.AddManipulator(new ClickActivatorConfigurable(1, MouseButton.RightMouse, SecondaryAction));
// Special action: Double middle-click
interactiveElement.AddManipulator(new ClickActivatorConfigurable(2, MouseButton.MiddleMouse, SpecialAction));

Member Function Documentation

◆ Init()

void GWG.WindowFramework.Manipulators.ClickActivatorConfigurable.Init ( int clickCount,
MouseButton button,
Action action )
private
Parameters
clickCountThe number of consecutive clicks required for activation
buttonThe mouse button that triggers the manipulator
actionThe action to execute when activation criteria are met

This private method centralizes the initialization logic to ensure consistent setup across all constructor overloads. It performs two primary operations:

Action Storage:

  • Stores the provided action delegate for later execution
  • Handles null actions gracefully (no operation when activated)

Activation Filter Configuration:

  • Creates a ManipulatorActivationFilter with the specified button and click count
  • Adds the filter to the manipulator's activators collection
  • Ensures the manipulator only responds to the exact specified input pattern

This centralized approach prevents code duplication and ensures that all instances of the manipulator are configured consistently regardless of which constructor is used.

// Init is called internally by all constructors:
// Single-parameter constructor:
// ↓ Calls Init(1, MouseButton.LeftMouse, MyAction)
// Two-parameter constructor:
// ↓ Calls Init(2, MouseButton.LeftMouse, MyAction)
// Three-parameter constructor:
new ClickActivatorConfigurable(2, MouseButton.RightMouse, MyAction)
// ↓ Calls Init(2, MouseButton.RightMouse, MyAction)
// All result in consistent internal configuration:
// - _action = MyAction
// - activators contains one filter with specified button and click count

◆ OnMouseDown()

void GWG.WindowFramework.Manipulators.ClickActivatorConfigurable.OnMouseDown ( MouseDownEvent evt)
private
Parameters
evtThe mouse down event data containing button information, position, and click count

This method is the core event handler that processes mouse input and determines whether to execute the configured action. It performs validation, action execution, and event management in a coordinated sequence:

Validation Process:

  • Uses CanStartManipulation() to check if the event matches activation criteria
  • Validates mouse button type against the configured button
  • Verifies click count matches the required number of clicks
  • Ensures the event is appropriate for manipulation

Action Execution:

  • Invokes the stored action delegate if it's not null
  • Handles null actions gracefully (no operation performed)
  • Action is executed immediately when criteria are met

Event Management:

  • Stops event propagation to prevent other handlers from processing the same event
  • Ensures clean event flow and prevents unintended side effects
  • Maintains proper event handling hierarchy

The method provides reliable click detection with proper isolation from other event handlers, making it suitable for complex UI scenarios with multiple overlapping interaction patterns.

// OnMouseDown is called automatically when user clicks the element
// Example validation and execution flow:
// 1. User double-clicks with right mouse button
// 2. OnMouseDown receives MouseDownEvent
// 3. CanStartManipulation() checks:
// - Button type: Right mouse ✓ (matches configuration)
// - Click count: 2 ✓ (matches configuration)
// - Event validity: ✓ (event is valid)
// 4. Action is executed: _action?.Invoke()
// 5. Event propagation stopped: evt.StopPropagation()
// Example with null action:
var eventBlocker = new ClickActivatorConfigurable(null);
// OnMouseDown will still stop propagation even with null action
// Useful for intercepting clicks without performing actions
// Example with complex action:
var complexClicker = new ClickActivatorConfigurable(() => {
try
{
ValidateState();
PerformOperation();
UpdateUI();
}
catch (Exception ex)
{
Debug.LogError($"Click action failed: {ex.Message}");
ShowErrorMessage();
}
});
// Event propagation behavior:
// Without StopPropagation(): Event continues to parent elements
// With StopPropagation(): Event stops at this element
// This prevents unwanted interactions with parent elements

◆ RegisterCallbacksOnTarget()

override void GWG.WindowFramework.Manipulators.ClickActivatorConfigurable.RegisterCallbacksOnTarget ( )
protected

This method is automatically called by Unity's UI Toolkit when the manipulator is added to a target element. It establishes the event handling chain that enables the manipulator to respond to mouse input.

Event Registration:

  • Registers a callback for MouseDownEvent
  • Uses the default event phase (bubble phase)
  • Connects the OnMouseDown method as the event handler

The MouseDownEvent is chosen because it provides the most reliable detection of click events, including proper click count tracking and button identification. The manipulator's activation filters ensure that only relevant events trigger the configured action.

// RegisterCallbacksOnTarget is called automatically when manipulator is added
var clicker = new ClickActivatorConfigurable(() => Debug.Log("Clicked"));
myElement.AddManipulator(clicker);
// ↑ Automatically calls RegisterCallbacksOnTarget()
// The registration establishes the event flow:
// User clicks element → MouseDownEvent → OnMouseDown() → Action execution
// Multiple manipulators can coexist:
element.AddManipulator(new ClickActivatorConfigurable(1, () => SingleClick()));
element.AddManipulator(new ClickActivatorConfigurable(2, () => DoubleClick()));
// Each manipulator registers its own MouseDownEvent callback
// Unity's event system handles the proper routing based on activation filters

◆ UnregisterCallbacksFromTarget()

override void GWG.WindowFramework.Manipulators.ClickActivatorConfigurable.UnregisterCallbacksFromTarget ( )
protected

This method is automatically called by Unity's UI Toolkit when the manipulator is removed from a target element or when the element is destroyed. It ensures proper cleanup of event handlers to prevent memory leaks and orphaned callbacks.

Cleanup Operations:

  • Removes the MouseDownEvent callback registration
  • Breaks the connection between the manipulator and the target element
  • Prevents the manipulator from continuing to process events after removal

Proper unregistration is essential for maintaining application performance and preventing unexpected behavior when elements are dynamically created and destroyed during the application lifecycle.

// UnregisterCallbacksFromTarget is called automatically when manipulator is removed
myElement.RemoveManipulator(existingClicker);
// ↑ Automatically calls UnregisterCallbacksFromTarget()
// Also called when element is destroyed
myElement.RemoveFromHierarchy();
// ↑ Triggers cleanup including callback unregistration
// After unregistration:
// - MouseDownEvent no longer routes to OnMouseDown()
// - No memory leaks from orphaned event handlers
// - Element can be safely garbage collected
// Good practice for dynamic UI:
void UpdateDynamicPanel()
{
// Remove old elements (automatic cleanup)
dynamicContainer.Clear();
// Add new elements with fresh manipulators
for (int i = 0; i < itemCount; i++)
{
var item = CreateItem(i);
item.AddManipulator(new ClickActivatorConfigurable(() => HandleItem(i)));
dynamicContainer.Add(item);
}
}

Member Data Documentation

◆ _action

Action GWG.WindowFramework.Manipulators.ClickActivatorConfigurable._action
private

This action is invoked when the manipulator detects a mouse click event that matches the configured activation criteria (button type and click count). The action can be null, in which case no operation is performed when the click is detected.

The action is executed immediately when the click pattern is recognized, and event propagation is automatically stopped to prevent other handlers from processing the same mouse event.