PopupField<T>
Generic popup selection field.
Read time 9 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: BasePopupField<T, T>
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IBindable, INotifyValueChanged<T>, IMixedValueSupport
public class PopupField<T> : BasePopupField<T, T>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IBindable, INotifyValueChanged<T>, IMixedValueSupport
Remarks
The following example shows how to create a popup field for a custom data type.
Examples
using System.Collections.Generic;using UnityEngine.UIElements;public class MyData{ public string name; public int id;}public class MyPopupField : PopupField<MyData>{ public MyPopupField() { // Add some example data choices = new List<MyData> { new MyData { name = "First", id = 1 }, new MyData { name = "Second", id = 2 }, new MyData { name = "Third", id = 3 }, }; index = 0; formatSelectedValueCallback = FormatItem; formatListItemCallback = FormatItem; } static string FormatItem(MyData myData) { return myData.name; }}
Static Fields
Value | Description |
|---|---|
| inputUssClassName | USS class name of input elements in elements of this type. |
| labelUssClassName | USS class name of labels in elements of this type. |
| ussClassName | USS class name of elements of this type. |
Constructors
Constructor | Description |
|---|---|
| PopupField`1() | Construct a PopupField. |
| PopupField`1(System.Collections.Generic.List{`0},`0,System.Func{`0,System.String},System.Func{`0,System.String}) | Construct a PopupField. |
| PopupField`1(System.Collections.Generic.List{`0},System.Int32,System.Func{`0,System.String},System.Func{`0,System.String}) | Construct a PopupField. |
| PopupField`1(System.String) | Construct a PopupField. |
| PopupField`1(System.String,System.Collections.Generic.List{`0},`0,System.Func{`0,System.String},System.Func{`0,System.String}) | Construct a PopupField. |
| PopupField`1(System.String,System.Collections.Generic.List{`0},System.Int32,System.Func{`0,System.String},System.Func{`0,System.String}) | Construct a PopupField. |
Properties
Property | Description |
|---|---|
| formatListItemCallback | Callback that provides a string representation used to populate the popup menu. |
| formatSelectedValueCallback | Callback that provides a string representation used to display the selected value. |
| index | The currently selected index in the popup menu. Setting the index updates the PopupField<T>.value field and sends a property change notification. |
| value | The currently selected value in the popup menu. |