Class ColorField
Color Field UI element.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public class ColorField : ExVisualElement, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Color>, IValidatableElement<Color>, INotifyValueChanging<Color>, INotifyValueChanged<Color>, ISizeableElement, IPressable
Constructors
ColorField()
Default constructor.
Declaration
public ColorField()
Fields
colorPickerIconUssClassName
The ColorField color picker icon styling class.
Declaration
public const string colorPickerIconUssClassName = "appui-colorfield__color-picker-icon"
Field Value
| Type | Description |
|---|---|
| string |
colorSwatchUssClassName
The ColorField color swatch styling class.
Declaration
public const string colorSwatchUssClassName = "appui-colorfield__color-swatch"
Field Value
| Type | Description |
|---|---|
| string |
inlinePickerOpenedUssClassName
The ColorField inline picker opened styling class.
Declaration
public const string inlinePickerOpenedUssClassName = "appui-colorfield--inline-picker-opened"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The ColorField label styling class.
Declaration
public const string labelUssClassName = "appui-colorfield__label"
Field Value
| Type | Description |
|---|---|
| string |
showTextUssClassName
The ColorField showText styling class.
Declaration
public const string showTextUssClassName = "appui-colorfield--show-text"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The ColorField size styling class.
Declaration
public const string sizeUssClassName = "appui-colorfield--size-"
Field Value
| Type | Description |
|---|---|
| string |
swatchOnlyUssClassName
The ColorField swatch only styling class.
Declaration
public const string swatchOnlyUssClassName = "appui-colorfield--swatch-only"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The ColorField main styling class.
Declaration
public const string ussClassName = "appui-colorfield"
Field Value
| Type | Description |
|---|---|
| string |
Properties
clickable
Clickable Manipulator for this AssetTargetField.
Declaration
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
colorPickerType
The ColorField color picker type.
Declaration
public ColorPickerType colorPickerType { get; set; }
Property Value
| Type | Description |
|---|---|
| ColorPickerType |
contentContainer
The content container of this ColorField. This is null for ColorField.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
customPicker
The custom color picker for the ColorField.
Declaration
public ICustomColorFieldPicker customPicker { get; set; }
Property Value
| Type | Description |
|---|---|
| ICustomColorFieldPicker |
Examples
// Example implementation of a custom color picker
public class CustomColorPicker : ICustomColorFieldPicker
{
private VisualElement m_PickerWindow;
private Action<Color> m_OnValueChanging;
private ColorField m_Owner;
private Color m_InitialColor;
public void Show(ColorField owner, Action<Color> onValueChanging, Color initialColor, bool showAlpha, bool hdr)
{
m_Owner = owner;
m_OnValueChanging = onValueChanging;
m_InitialColor = initialColor;
// Create custom picker UI
m_PickerWindow = new VisualElement { name = "custom-picker" };
// Setup picker with callbacks
var picker = new MyCustomPickerUI(initialColor, showAlpha, hdr);
picker.onColorChanged += (color) =>
{
// Send ChangingEvent while picker is still open
m_OnValueChanging?.Invoke(color);
};
picker.onColorAccepted += (color) =>
{
// Send final ChangeEvent like the default implementation
using var evt = ChangeEvent<Color>.GetPooled(m_InitialColor, color);
evt.target = m_Owner;
m_Owner.SetValueWithoutNotify(color);
m_Owner.SendEvent(evt);
ClosePickerWindow();
};
picker.onCanceled += () =>
{
// Revert to initial color
m_OnValueChanging?.Invoke(m_InitialColor);
ClosePickerWindow();
};
m_PickerWindow.Add(picker);
owner.rootVisualElement.Add(m_PickerWindow);
}
private void ClosePickerWindow()
{
m_PickerWindow?.RemoveFromHierarchy();
m_OnValueChanging = null;
m_Owner?.Focus();
}
}
// Usage:
var colorField = new ColorField();
colorField.customPicker = new CustomColorPicker();
hdr
Whether to show the HDR colors in the ColorPicker.
Declaration
public bool hdr { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
inlinePicker
The ColorPicker position relative to the ColorField. When this is true, the ColorPicker will be inlined instead of being displayed in a Popover.
Declaration
public bool inlinePicker { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
invalid
The ColorField invalid state.
Declaration
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
showAlpha
Whether to show the alpha channel in the ColorPicker.
Declaration
public bool showAlpha { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
showText
Whether to show the text label for the ColorField.
Declaration
public bool showText { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The ColorField size.
Declaration
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
swatchOnly
The ColorField type. When this is true, the ColorField will only show the swatch.
Declaration
public bool swatchOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
swatchSize
The ColorField swatch size.
Declaration
public Size swatchSize { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
validateValue
The ColorField validation function.
Declaration
public Func<Color, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Color, bool> |
value
The ColorField value.
Declaration
public Color value { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
SetValueWithoutNotify(Color)
Sets the ColorField value without notifying the ColorField.
Declaration
public void SetValueWithoutNotify(Color newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | newValue | The new ColorField value. |