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

Represents a user interface element for configuring context menu settings within the window framework. This form element allows customization of various context menu behaviors, such as fade time and delay. More...

Inheritance diagram for GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement:

Public Member Functions

 ContextMenuSettingsFormElement ()
 Initializes a new instance of the ContextMenuSettingsFormElement class.
VisualElement CreateFormElement ()
 Creates and configures the visual structure for the context menu settings form.

Properties

float ContextMenuDelay [get, set]
 Gets or sets the delay (in seconds) before the context menu begins to fade out.
float ContextMenuFadeTime [get, set]
 Gets or sets the duration (in seconds) for the fade animation of a context menu.

Private Member Functions

 ~ContextMenuSettingsFormElement ()
 Finalizer that ensures proper cleanup of event callbacks when the object is destroyed.
void Callback (GeometryChangedEvent evt)
 Callback method executed when the geometry of the element changes for the first time.
void RegisterCallbacks ()
 Registers event callbacks for the slider controls to handle value changes.

Private Attributes

float _contentMenuDelay
 Backing field for the ContextMenuDelay property. Stores the delay before context menus begin to fade out.
float _contentMenuFadeTime
 Backing field for the ContextMenuFadeTime property.
Slider _contextMenuFadeDelaySlider
 Slider control for adjusting the context menu fade delay.
Slider _contextMenuFadeTimeSlider
 Slider control for adjusting the context menu fade time.

Detailed Description

This class extends VisualElement and provides a user interface for configuring context menu animation settings. It includes sliders for adjusting fade time and fade delay, and automatically synchronizes these values with the WindowFrameController instance.

The form element is designed to be used in Unity's UI Toolkit system and can be instantiated both programmatically and through UXML markup.

// Create and add to a parent container
var parentContainer = new VisualElement();
var contextMenuSettings = new ContextMenuSettingsFormElement();
parentContainer.Add(contextMenuSettings);
// Access properties directly
contextMenuSettings.ContextMenuFadeTime = 0.3f;
contextMenuSettings.ContextMenuDelay = 1.5f;
ContextMenuSettingsFormElement()
Initializes a new instance of the ContextMenuSettingsFormElement class.
Definition ContextMenuSettingsFormElement.cs:189

Constructor & Destructor Documentation

◆ ContextMenuSettingsFormElement()

GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement.ContextMenuSettingsFormElement ( )

The constructor performs the following operations:

  • Sets the flex-shrink style property to 0 to prevent unwanted resizing
  • Initializes backing fields with values from WindowFrameController if available
  • Creates and adds the form element UI structure
  • Registers a one-time geometry changed callback to initialize slider values

The UI elements are created immediately, but their values are synchronized after the first geometry change event to ensure proper initialization timing.

// Create a new context menu settings form
var contextMenuSettings = new ContextMenuSettingsFormElement();
// Add to a parent container
var settingsPanel = new VisualElement();
settingsPanel.Add(contextMenuSettings);
// Or add directly to root visual element
rootVisualElement.Add(contextMenuSettings);

◆ ~ContextMenuSettingsFormElement()

GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement.~ContextMenuSettingsFormElement ( )
private

This finalizer attempts to unregister the value changed callbacks from the slider controls to prevent memory leaks. However, due to the nature of finalizers in .NET, this cleanup is not guaranteed to execute in a timely manner.

Note: In practice, Unity's UI Toolkit automatically handles cleanup of visual element callbacks when elements are removed from the visual tree, so this finalizer serves as additional safety measure.

For more predictable cleanup, consider implementing System.IDisposable and calling cleanup methods explicitly when the element is no longer needed.

Member Function Documentation

◆ Callback()

void GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement.Callback ( GeometryChangedEvent evt)
private
Parameters
evtThe geometry changed event arguments.

This method is called once after the element is laid out and performs initial value synchronization between the properties and the UI sliders. It also registers the ongoing value change callbacks for the sliders.

The delayed initialization ensures that the WindowFrameController instance is available and the UI elements are properly created before attempting to set their values.

◆ CreateFormElement()

VisualElement GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement.CreateFormElement ( )
Returns
A VisualElement containing the complete form structure with title, sliders, and appropriate styling classes.

This method constructs the following UI hierarchy:

  • Root container with "context-menu-settings-form" class
  • Title label with "Context Menu Settings" text
  • Elements container holding the slider controls
  • Fade delay slider (0-5 seconds range)
  • Fade time slider (0-3 seconds range)

Both sliders include input fields for precise value entry and tooltips for user guidance. The method applies appropriate CSS classes for styling integration.

// Typically called internally, but can be used to recreate the form
var formElement = contextMenuSettings.CreateFormElement();
// Add additional elements to the form if needed
var customElement = new Label("Additional Settings");
formElement.Add(customElement);

◆ RegisterCallbacks()

void GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement.RegisterCallbacks ( )
private

This method sets up bidirectional binding between the slider controls and the corresponding properties. When a user moves a slider, the associated property is automatically updated, which in turn updates the WindowFrameController if available.

The method includes a safety check to ensure the WindowFrameController instance exists before registering callbacks to prevent null reference exceptions.

Registered callbacks:

// This method is called automatically during initialization
// Manual call might be needed if recreating the UI elements
contextMenuSettings.RegisterCallbacks();

Member Data Documentation

◆ _contentMenuDelay

float GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement._contentMenuDelay
private

◆ _contentMenuFadeTime

float GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement._contentMenuFadeTime
private

◆ _contextMenuFadeDelaySlider

Slider GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement._contextMenuFadeDelaySlider
private

This slider provides a user interface for modifying the ContextMenuDelay property. It has a range from 0.0f to 5.0f seconds with a page size of 0.1f for fine adjustments.

◆ _contextMenuFadeTimeSlider

Slider GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement._contextMenuFadeTimeSlider
private

This slider provides a user interface for modifying the ContextMenuFadeTime property. It has a range from 0.0f to 3.0f seconds with input field support for precise value entry.

Property Documentation

◆ ContextMenuDelay

float GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement.ContextMenuDelay
getset

A float value representing the delay duration in seconds before fade out begins. Valid range is typically 0.0f to 5.0f seconds.

This property specifies the waiting period before the fade-out animation of a context menu is triggered. Modifying this value allows you to customize the timing of context menu closure after being dismissed. A longer delay gives users more time to interact with the menu, while a shorter delay makes the interface more responsive but potentially less user-friendly.

The property automatically synchronizes with the WindowFrameController instance when available, ensuring that changes are immediately applied to the application's behavior.
See: WindowFrameController.ContextMenuFadeDelay

// Set context menu fade delay to 1 second for better usability
contextMenuSettingsFormElement.ContextMenuDelay = 1f;
// Set a shorter delay for more responsive UI
contextMenuSettingsFormElement.ContextMenuDelay = 0.2f;
// Get current delay value
float currentDelay = contextMenuSettingsFormElement.ContextMenuDelay;

◆ ContextMenuFadeTime

float GWG.WindowFramework.FormElements.ContextMenuSettingsFormElement.ContextMenuFadeTime
getset

A float value representing the fade animation duration in seconds. Valid range is typically 0.0f to 3.0f seconds.

This property determines the time it takes for the context menu to fade in or out when displayed or dismissed. Adjusting this value can modify the user interface experience by making transitions appear faster or slower.

The property automatically synchronizes with the WindowFrameController instance when available, ensuring that changes are immediately reflected in the application's behavior.
See: WindowFrameController.ContextMenuFadeTime
See: WindowFrameController.ContextMenuFadeDelay

// Set context menu fade time to 0.5 seconds for smooth transitions
contextMenuSettingsFormElement.ContextMenuFadeTime = 0.5f;
// Get current fade time
float currentFadeTime = contextMenuSettingsFormElement.ContextMenuFadeTime;
Debug.Log($"Current fade time: {currentFadeTime} seconds");