|
UsoUIElements 0.1.0
Data Centric implimentation of Unity's UI Elements (UI Toolkit)
|
A static utility class that provides helper methods and extensions for working with Unity's UI Elements system. This class offers functionality for field validation styling, LINQ-style query operations, element creation, manipulation, and traversal. More...
Static Public Member Functions | |
| static void | AddClass (this VisualElement ele, string className) |
| Adds a single CSS class to a VisualElement with null-checking for safety. This method provides a safe way to add CSS classes with proper error handling. | |
| static T | AddClass< T > (this T visualElement, params string[] classes) |
| Adds multiple CSS classes to a VisualElement and returns the element for method chaining. This method provides a fluent interface for applying multiple CSS classes in a single operation. | |
| static void | AddClickListener (this VisualElement ele, EventCallback< ClickEvent > callback) |
| Adds a click event listener to a VisualElement with null-checking for safety. This method provides a convenient way to register click event handlers. | |
| static T | AddTo< T > (this T child, VisualElement parent) |
| Adds the specified child element to a parent element and returns the child for method chaining. This method enables fluent interface patterns for element hierarchy construction. | |
| static int | CountWhere< T > (this UQueryBuilder< T > query, Func< T, bool > predicate) |
| Extends UQueryBuilder with LINQ-style Count functionality to count elements that satisfy a specified condition. Converts the query to a list and applies the predicate function to count matching elements. | |
| static VisualElement | CreateChild (this VisualElement parent, params string[] classes) |
| Creates a new child VisualElement, applies optional CSS classes, and adds it to the specified parent element. This method provides a fluent interface for rapid UI construction. | |
| static T | CreateChild< T > (this VisualElement parent, params string[] classes) |
| Creates a new child element of the specified type, applies optional CSS classes, and adds it to the specified parent element. This generic method allows creation of specific VisualElement types with fluent interface support. | |
| static VisualElement | FindChildByName (this VisualElement ele, string name) |
| Recursively searches for a child element with the specified name within the visual hierarchy. This method performs a depth-first search through all descendants of the starting element. | |
| static T | FirstOrDefault< T > (this UQueryBuilder< T > query) |
| Extends UQueryBuilder with LINQ-style FirstOrDefault functionality to return the first element or a default value. Converts the query to a list and returns the first element, or null if the sequence is empty. | |
| static VisualElement | GetDocumentRoot (this VisualElement ele) |
| Recursively traverses up the visual hierarchy to find and return the root element of the document. This method climbs the parent chain until it reaches an element with no parent. | |
| static bool | IsVisible (this VisualElement ele) |
| Determines whether a VisualElement is currently visible by checking its display style. Returns true if the element's display style is not set to None. | |
| static IEnumerable< T > | OrderBy< T, TKey > (this UQueryBuilder< T > query, Func< T, TKey > keySelector, Comparer< TKey > @default) |
| Extends UQueryBuilder with LINQ-style OrderBy functionality to sort elements in ascending order according to a key. Converts the query to a list and applies standard LINQ OrderBy with the provided key selector and comparer. | |
| static void | RemoveClass (this VisualElement ele, string className) |
| Removes a CSS class from a VisualElement with null-checking for safety. This method provides a safe way to remove CSS classes with proper error handling. | |
| static void | SetFieldStatus (VisualElement element, FieldStatusTypes fieldStatus) |
| Sets the field validation status for a visual element by applying the appropriate CSS class. Removes any existing validation classes and applies the class corresponding to the specified status. | |
| static IEnumerable< T > | SortByNumericValue< T > (this UQueryBuilder< T > query, Func< T, float > keySelector) |
| Extends UQueryBuilder with functionality to sort elements by a numeric key in ascending order. This is a specialized version of OrderBy optimized for numeric sorting operations. | |
| static void | ToggleClass (this VisualElement ele, string className) |
| Toggles a CSS class on a VisualElement (adds if not present, removes if present) with null-checking for safety. This method provides a convenient way to toggle CSS classes for state changes. | |
| static void | ToggleVisibility (this VisualElement ele) |
| Toggles the visibility of a VisualElement between visible (Flex) and hidden (None) display states. This method provides a convenient way to show/hide elements with a single method call. | |
| static T | WithManipulator< T > (this T visualElement, IManipulator manipulator) |
| Adds a manipulator to a VisualElement and returns the element for method chaining. This method enables fluent interface patterns for adding interaction manipulators. | |
Static Public Attributes | |
| static List< string > | FieldValidationClasses |
| A list of CSS class names used for field validation status styling. These classes correspond to different validation states and are used for visual feedback. | |
A static utility class that provides helper methods and extensions for working with Unity's UI Elements system. This class offers functionality for field validation styling, LINQ-style query operations, element creation, manipulation, and traversal.
The UsoUiHelper class serves as the central utility hub for the Uso UI Elements system, providing:
All methods are designed to follow fluent interface patterns where applicable, allowing for method chaining. The class integrates with the broader Uso UI validation system through standardized CSS class naming conventions.
|
static |
Adds a single CSS class to a VisualElement with null-checking for safety. This method provides a safe way to add CSS classes with proper error handling.
| ele | The VisualElement to add the class to. |
| className | The CSS class name to add. |
| ArgumentNullException | Thrown when the element parameter is null. |
This method provides explicit null-checking and clear error messages for debugging purposes. It's designed for scenarios where you need guaranteed safety and clear error reporting.
|
static |
Adds multiple CSS classes to a VisualElement and returns the element for method chaining. This method provides a fluent interface for applying multiple CSS classes in a single operation.
| T | The type of the VisualElement. |
| visualElement | The VisualElement to add classes to. |
| classes | Array of CSS class names to add to the element. |
This method iterates through the provided class names and applies each non-null and non-empty class to the element. It supports the fluent interface pattern for streamlined element styling during creation. Null or empty class names are safely ignored without throwing exceptions.
| T | : | VisualElement |
|
static |
Adds a click event listener to a VisualElement with null-checking for safety. This method provides a convenient way to register click event handlers.
| ele | The VisualElement to add the click listener to. |
| callback | The event callback to execute when the element is clicked. |
| ArgumentNullException | Thrown when the element parameter is null. |
This method simplifies the common pattern of adding click event handlers to UI elements. It provides explicit null-checking and a more readable method name than the generic RegisterCallback.
|
static |
Adds the specified child element to a parent element and returns the child for method chaining. This method enables fluent interface patterns for element hierarchy construction.
| T | The type of the child VisualElement. |
| child | The child element to be added to the parent. |
| parent | The parent VisualElement to add the child to. |
This extension method supports fluent interface patterns by allowing element creation and parenting to be chained with other operations. It's designed to work seamlessly with other fluent methods in this class to enable readable and concise UI construction code.
| T | : | VisualElement |
|
static |
Extends UQueryBuilder with LINQ-style Count functionality to count elements that satisfy a specified condition. Converts the query to a list and applies the predicate function to count matching elements.
| T | The type of VisualElement being queried. |
| query | The UQueryBuilder containing the sequence of elements to be processed. |
| predicate | A function to test each element for a condition. |
This method enables conditional counting operations on UI element queries, useful for validation scenarios, state analysis, or determining the presence of elements with specific characteristics. The predicate function is applied to each element, and only elements that return true are counted.
| T | : | VisualElement |
|
static |
Creates a new child VisualElement, applies optional CSS classes, and adds it to the specified parent element. This method provides a fluent interface for rapid UI construction.
| parent | The parent VisualElement to add the new child to. |
| classes | Optional array of CSS class names to apply to the new child element. |
This method streamlines the common pattern of creating, styling, and parenting UI elements in a single operation. It uses the fluent interface pattern to allow for readable and concise UI construction code. The method applies classes and parents the element in one atomic operation for convenience.
|
static |
Creates a new child element of the specified type, applies optional CSS classes, and adds it to the specified parent element. This generic method allows creation of specific VisualElement types with fluent interface support.
| T | The specific type of VisualElement to create, must have a parameterless constructor. |
| parent | The parent VisualElement to add the new child to. |
| classes | Optional array of CSS class names to apply to the new child element. |
This generic version of CreateChild allows for creating specific UI element types (like Button, Label, TextField, etc.) while maintaining the fluent interface pattern. It's particularly useful when you need to manipulate the created element further and want to maintain the specific type rather than working with the base VisualElement type. The return type is the specific element type, allowing immediate access to type-specific properties and methods.
| T | : | VisualElement | |
| T | : | new() |
|
static |
Recursively searches for a child element with the specified name within the visual hierarchy. This method performs a depth-first search through all descendants of the starting element.
| ele | The starting VisualElement to begin the search from. |
| name | The name of the child element to find. |
| ArgumentNullException | Thrown when the element parameter is null. |
| ArgumentException | Thrown when the name parameter is null or empty. |
This method performs a recursive depth-first search through the entire visual tree starting from the specified element. It checks immediate children first, then recursively searches within each child's hierarchy. The search returns the first matching element found, so element names should be unique within the search scope for predictable results. This method is useful for finding elements by their programmatically assigned names when direct references are not available.
|
static |
Extends UQueryBuilder with LINQ-style FirstOrDefault functionality to return the first element or a default value. Converts the query to a list and returns the first element, or null if the sequence is empty.
| T | The type of VisualElement being queried. |
| query | The UQueryBuilder containing the elements to search. |
This extension method provides safe access to the first element in a query result without throwing exceptions when the sequence is empty. It's particularly useful for optional element lookups where the absence of an element is a valid scenario that should be handled gracefully.
| T | : | VisualElement |
|
static |
Recursively traverses up the visual hierarchy to find and return the root element of the document. This method climbs the parent chain until it reaches an element with no parent.
| ele | The starting VisualElement to begin the traversal from. |
| ArgumentNullException | Thrown when the element parameter is null. |
This method uses recursion to traverse up the visual tree until it finds the root element. It's useful for accessing document-level properties or performing operations that require knowledge of the complete hierarchy context. The root element is typically the UIDocument's root visual element.
|
static |
Determines whether a VisualElement is currently visible by checking its display style. Returns true if the element's display style is not set to None.
| ele | The VisualElement to check for visibility. |
| ArgumentNullException | Thrown when the element parameter is null. |
This method checks the resolved display style to determine actual visibility state. It's useful for conditional logic that depends on element visibility without directly checking CSS properties. Note that this only checks the display property and doesn't account for other factors like opacity or parent visibility.
|
static |
Extends UQueryBuilder with LINQ-style OrderBy functionality to sort elements in ascending order according to a key. Converts the query to a list and applies standard LINQ OrderBy with the provided key selector and comparer.
| T | The type of VisualElement being queried. |
| TKey | The type of the key used for sorting. |
| query | The UQueryBuilder containing the elements to be sorted. |
| keySelector | A function to extract a sort key from each element. |
| default | The Comparer to use for comparing keys. |
This extension method bridges the gap between Unity's UQueryBuilder system and standard LINQ operations. It materializes the query results into a list before applying the ordering operation. The method allows for custom comparison logic through the comparer parameter.
| T | : | VisualElement |
|
static |
Removes a CSS class from a VisualElement with null-checking for safety. This method provides a safe way to remove CSS classes with proper error handling.
| ele | The VisualElement to remove the class from. |
| className | The CSS class name to remove. |
| ArgumentNullException | Thrown when the element parameter is null. |
This method provides explicit null-checking and clear error messages for debugging purposes. It safely removes the specified class if it exists, with no effect if the class is not present.
|
static |
Sets the field validation status for a visual element by applying the appropriate CSS class. Removes any existing validation classes and applies the class corresponding to the specified status.
| element | The VisualElement to apply the status styling to. |
| fieldStatus | The field status type to apply. |
This method first removes all validation classes from the element to ensure a clean state, then applies the appropriate class based on the fieldStatus parameter. The Default status results in no additional classes being applied, allowing the element to use its base styling.
The method is central to the Uso UI validation system and ensures consistent visual feedback across all form elements that implement field validation.
|
static |
Extends UQueryBuilder with functionality to sort elements by a numeric key in ascending order. This is a specialized version of OrderBy optimized for numeric sorting operations.
| T | The type of VisualElement being queried. |
| query | The UQueryBuilder containing the elements to be sorted. |
| keySelector | A function to extract a numeric key from each element. |
This method provides a convenient way to sort UI elements by numeric properties such as positions, sizes, or custom numeric attributes. It uses the default float comparer for consistent sorting behavior. Common use cases include sorting elements by their layout positions or custom numeric data attributes.
| T | : | VisualElement |
|
static |
Toggles a CSS class on a VisualElement (adds if not present, removes if present) with null-checking for safety. This method provides a convenient way to toggle CSS classes for state changes.
| ele | The VisualElement to toggle the class on. |
| className | The CSS class name to toggle. |
| ArgumentNullException | Thrown when the element parameter is null. |
This method is particularly useful for implementing toggle behaviors, hover effects, or state changes where a CSS class represents a binary state. It provides explicit null-checking for safety.
|
static |
Toggles the visibility of a VisualElement between visible (Flex) and hidden (None) display states. This method provides a convenient way to show/hide elements with a single method call.
| ele | The VisualElement to toggle visibility for. |
| ArgumentNullException | Thrown when the element parameter is null. |
This method toggles between DisplayStyle.None (hidden) and DisplayStyle.Flex (visible). It's commonly used for implementing show/hide functionality, collapsible sections, or modal dialogs. The method preserves the element's layout properties when visible by using Flex display mode.
|
static |
Adds a manipulator to a VisualElement and returns the element for method chaining. This method enables fluent interface patterns for adding interaction manipulators.
| T | The type of the VisualElement. |
| visualElement | The VisualElement to add the manipulator to. |
| manipulator | The IManipulator to add to the element. |
This method supports fluent interface patterns by allowing manipulator addition to be chained with other element configuration operations. Manipulators handle complex interactions like dragging, resizing, or custom gesture recognition.
| T | : | VisualElement |
|
static |
A list of CSS class names used for field validation status styling. These classes correspond to different validation states and are used for visual feedback.
The list contains predefined CSS class names for all supported field validation states:
These classes should have corresponding styles defined in the project's CSS to provide appropriate visual feedback.