EditableLabel Class

Description

A label that transforms into a field for editing its text. UXML support

public class EditableLabel : BindableElement, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle, IBindable, INotifyValueChanged<string>
Inheritance
Remarks

By default, it becomes editable with a double click. Use BeginEditing() to enter edit mode from code. Set emptyTextLabel to show a placeholder text when the label is empty.

Examples

Here's an example for customizing an editable label.

public class MyCustomEditor : Editor
{
    public override VisualElement CreateInspectorGUI()
    {
        var root = new VisualElement();
        var editableLabel = new EditableLabel();
        root.Add(editableLabel);

        // We can disable editing on double click this way:
        editableLabel.editOnDoubleClick = false;

        // EditableLabels can enter edit mode from code. 
        // For example, we can add a listener to edit it on Alt+Click:
        editableLabel.RegisterCallback<MouseDownEvent>(e =>
        {
            if (e.altKey && e.button == 0)
                editableLabel.BeginEditing();
        });

        // We can also make it editable from a context menu action:
        var menuManipulator = new ContextualMenuManipulator(e =>
        {
            e.menu.AppendAction("Edit label's text", a => editableLabel.BeginEditing());
        });
        root.AddManipulator(menuManipulator);

        // We can add a placeholder text for when the label is empty:
        editableLabel.emptyTextLabel = "Alt+Click to edit this label";
        // Or we can set the label's actual text like this:
        editableLabel.value = "Initial text";

        // EditableLabels can be bound to any string property, just like any
        // TextField. We can do it by setting it's bindingPath:
        editableLabel.bindingPath = "m_Name";

        return root;
    }
}

Constructors

EditableLabel()

Fields

labelUssClassName

USS class name of the label used to show non-editable text.

textFieldUssClassName

USS class name of the TextField inside this element.

ussClassName

USS class name of elements of this type.

Properties

editOnDoubleClick

Whether to start editing by double clicking the label. See BeginEditing() to start editing from code.

emptyTextLabel

A text that appears when the EditableLabel's text is empty.

isDelayed

Whether the TextField inside this element is delayed. It's true by default.

maxLength

The maximum character length of this element's TextField. -1 means no limit and it's the default.

multiline

Whether to use multiline text.

value

The string value of this element.

Methods

BeginEditing()

Call this method to put the label in edit mode.

SetValueWithoutNotify(String)

Set the element's value without triggering a change event.

Extension Methods

UIToolkitExtensions.GetLocalRect(VisualElement)
UIToolkitExtensions.GetChildren<TElement>(VisualElement, List<TElement>, Func<TElement, Boolean>)
UIToolkitExtensions.GetFirstChild<TElement>(VisualElement, Func<TElement, Boolean>)
UIToolkitExtensions.ForEachChild<TElement>(VisualElement, Action<TElement>)
UIToolkitExtensions.GetBoundSerializedProperty(IBindable)