Class RectField
A specialized input field for editing Unity Rect values with position and size components.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class RectField : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Rect>, IValidatableElement<Rect>, ISizeableElement, INotifyValueChanging<Rect>, INotifyValueChanged<Rect>
Remarks
The RectField component provides a specialized input interface for editing Unity Rect values. It breaks down the rect into its four components - X, Y (position) and Width, Height (size) - making it easier to edit rect values in a structured way.
The field is organized in two rows - one for position (X,Y) and one for size (Width,Height) - each with clear labels and numeric inputs. Each numeric component is implemented as a FloatField, providing precise control over the values.
All numeric inputs support keyboard input, validation, and optional value constraints. The component maintains the integrity of the Rect structure while allowing independent editing of its components.
Examples
Basic RectField Usage
// Create a new RectField
var rectField = new RectField();
// Set initial value
rectField.value = new Rect(0, 0, 100, 100);
// Register for value changes
rectField.RegisterValueChangedCallback(evt => {
Debug.Log($"New rect: ");
});
RectField with Validation
var rectField = new RectField();
// Set up validation for positive values within bounds
rectField.validateValue = (rect) => {
return rect.width > 0 && rect.height > 0 &&
rect.x >= 0 && rect.y >= 0 &&
rect.x + rect.width <= Screen.width &&
rect.y + rect.height <= Screen.height;
};
// Handle invalid values
rectField.RegisterCallback<ChangeEvent<Rect>>(evt => {
if (rectField.invalid)
{
Debug.LogWarning("Invalid rectangle dimensions");
}
});
UXML Usage Example
<UXML xmlns:ui="UnityEngine.UIElements" xmlns:appui="Unity.AppUI.UI">
<appui:RectField
size="M"
value="0, 0, 100, 100"
style="width: 300px;"/>
</UXML>
Constructors
RectField()
Default constructor.
Declaration
public RectField()
Fields
hFieldUssClassName
The RectField H NumericalField styling class.
Declaration
public const string hFieldUssClassName = "appui-rectfield__h-field"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The RectField Label styling class.
Declaration
public const string labelUssClassName = "appui-rectfield__label"
Field Value
| Type | Description |
|---|---|
| string |
rowUssClassName
The RectField row styling class.
Declaration
public const string rowUssClassName = "appui-rectfield__row"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The RectField size styling class.
Declaration
public const string sizeUssClassName = "appui-rectfield--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The RectField main styling class.
Declaration
public const string ussClassName = "appui-rectfield"
Field Value
| Type | Description |
|---|---|
| string |
wFieldUssClassName
The RectField W NumericalField styling class.
Declaration
public const string wFieldUssClassName = "appui-rectfield__w-field"
Field Value
| Type | Description |
|---|---|
| string |
xFieldUssClassName
The RectField X NumericalField styling class.
Declaration
public const string xFieldUssClassName = "appui-rectfield__x-field"
Field Value
| Type | Description |
|---|---|
| string |
yFieldUssClassName
The RectField Y NumericalField styling class.
Declaration
public const string yFieldUssClassName = "appui-rectfield__y-field"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The content container of the RectField.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
invalid
The invalid state of the RectField.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The size of the RectField.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
validateValue
The validation function of the RectField.
Declaration
[CreateProperty]
public Func<Rect, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Rect, bool> |
value
The value of the RectField.
Declaration
[CreateProperty]
[UxmlAttribute]
public Rect value { get; set; }
Property Value
| Type | Description |
|---|---|
| Rect |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetValueWithoutNotify(Rect)
Set the value of the RectField without notifying the change.
Declaration
public void SetValueWithoutNotify(Rect newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Rect | newValue | The new value of the RectField. |