I am trying to create a custom inspector with UI Elements and the UI Builder. Is there a way to make the Text Field behave like a TextArea would in the classic inspector? I.e. having controls for resizing and scrolling the text, and the text being aligned top left instead of center left?
Hi @Chris_Entropy !
I am not sure what you mean by having a TextField that behaves like a TextArea.
- Scrolling the text can be achieved through the C# API like so:
inputField.SetVerticalScrollerVisibility(ScrollerVisibility.Auto);
- As for text alignment, this can be done in the UIbuilder in the Text foldout:
Thanks for the quick reply. I got text alignment covered with the USS file. I can’t edit the TextInput alignment directly, only that of the TextField caption label. In the version (Unity 2020.3.27f1, Unity UI 1.0.0, UI Builder 1.0.0 preview 18) I am using, the SetVerticalScrollerVisibility does not seem to exist, unfortunately. Maybe I need to live with it or upgrade.
Indeed, the scrollbar is a feature that was added in 2022.1.
As for the styling of the TextField, it seems like the “-unity-text-align” style doesn’t propagate to children. It’s unfortunate, and I’ll take some notes to address this in the future, but in the meantime, you can work around this. First, note that TextField is a “composite root” which means it has children. You can target the TextField children to apply styling to them like so:
textField.Q("unity-text-input").style.unityTextAlign = ...
(this is pseudoCode, I haven’t tested it. Note that it could also be done through USS)
“unity-text-input” doesn’t work. Correct class to target is “unity-base-text-field__input”.