Class ColorGradientField
A field that previews a Gradient and opens a gradient editor when pressed.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class ColorGradientField : ExVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Gradient>, IValidatableElement<Gradient>, INotifyValueChanging<Gradient>, INotifyValueChanged<Gradient>, ISizeableElement, IPressable
Remarks
The preview is a full-bleed ColorSwatch, so the color × alpha composite over the transparency checkerboard is rendered by the same shader the rest of the color family uses rather than by a second render path.
Like ColorField, the field and its editor are separable: the editor arrives through customPicker. With no picker assigned the control is still a useful, correct gradient display — which is why it ships ahead of the editor.
Example
var gradient = new Gradient();
gradient.SetKeys(
new[] { new GradientColorKey(Color.red, 0f), new GradientColorKey(Color.blue, 1f) },
new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) });
var field = new ColorGradientField { value = gradient };
UXML
<appui:ColorGradientField size="Md" hdr="false" />
Constructors
ColorGradientField()
Default constructor.
Declaration
public ColorGradientField()
Fields
sizeUssClassName
The ColorGradientField size styling class.
Declaration
public const string sizeUssClassName = "appui-colorgradientfield--size-"
Field Value
| Type | Description |
|---|---|
| string |
swatchUssClassName
The ColorGradientField swatch styling class.
Declaration
public const string swatchUssClassName = "appui-colorgradientfield__swatch"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The ColorGradientField main styling class.
Declaration
public const string ussClassName = "appui-colorgradientfield"
Field Value
| Type | Description |
|---|---|
| string |
Properties
clickable
Clickable Manipulator for this ColorGradientField.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
contentContainer
The content container of this element.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
customPicker
The editor opened when the field is pressed. Null by default.
Declaration
[CreateProperty]
public ICustomColorGradientFieldPicker customPicker { get; set; }
Property Value
| Type | Description |
|---|---|
| ICustomColorGradientFieldPicker |
hdr
Whether the editor should offer HDR color keys. Forwarded to customPicker; it does not change the preview.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool hdr { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
invalid
Whether the current value is valid, as determined by validateValue.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The size of the element.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
swatchElement
The ColorSwatch that renders the preview.
Declaration
public ColorSwatch swatchElement { get; }
Property Value
| Type | Description |
|---|---|
| ColorSwatch |
validateValue
A function that validates the value of the ColorGradientField.
Declaration
[CreateProperty]
public Func<Gradient, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Gradient, bool> |
value
The current value of the ColorGradientField.
Declaration
[CreateProperty]
public Gradient value { get; set; }
Property Value
| Type | Description |
|---|---|
| Gradient |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
OpenPicker()
Opens customPicker, as pressing the field does.
Declaration
public void OpenPicker()
SetValueWithoutNotify(Gradient)
Sets the value without sending a change event.
Declaration
public void SetValueWithoutNotify(Gradient newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Gradient | newValue | The new gradient. |
Events
pickRequested
Raised when the user asks for the editor, whether or not a customPicker is assigned.
Declaration
public event Action pickRequested
Event Type
| Type | Description |
|---|---|
| Action |