I’m attempting to create an inline drop-down menu using the PopupField class. Unfortunately, it seems like the size logic for this class is pretty strange. If I put it inline with some text, the content gets truncated in a weird way:
This is just using the code from the UIElements samples:
var choices = new List<string> { "First", "Second", "Third" };
// Create a new field and assign it its value.
var normalField = new PopupField<string>(choices, 0) {value = "Second"};
var row = new VisualElement();
row.style.flexDirection = FlexDirection.Row;
row.Add(new Label("Hello"));
row.Add(normalField);
root.Add(row);
Is there some way to accomplish this kind of inline dropdown functionality? (I know you can set a label on the PopupField, but I don’t like how that works… I want this dropdown to render inline).
I’m also interested in rendering two Popups next to each other, and this doesn’t work either:
By looking at your images it seems that an element is clipping the Popup. You can use the UIElements debugger to inspect the overflow property of your elements.
I also made a small script that render Popups next to each other and it works as expected.
public class PopupRow : EditorWindow
{
[MenuItem("UIElements/PopupRow")]
public static void ShowExample()
{
var wnd = GetWindow<PopupRow>();
wnd.titleContent = new GUIContent("PopupRow");
}
public void OnEnable()
{
var root = rootVisualElement;
var choices = new List<string> { "First", "Second", "Third" };
// Create a new field and assign it its value.
var normalField = new PopupField<string>(choices, 0) {value = "First"};
var row = new VisualElement();
row.style.flexDirection = FlexDirection.Row;
row.Add(normalField);
var field2 = new PopupField<string>(choices, 0) {value = "Second"};
row.Add(field2);
var field3 = new PopupField<string>(choices, 0) {value = "Third"};
row.Add(field3);
root.Add(row);
}
}
I just tested with the latest 2019.2 release and you’re right that this doesn’t work, sorry about that.
Yes it is fixed on 2019.3 and up.
This is clearly a layout bug and I’m not sure when this was actually fixed.
If this is a problem for you on 2019.2, feel free to report a bug with the bug reporter (Help → Report a bug).
A quick work around would be to set the width of the Popup inside the USS.