Search Unity

Popupfield has no uxml, is there a way to include it in the layout?

Discussion in 'UI Toolkit' started by MostHated, Nov 15, 2019.

  1. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    I am not sure how to go about inserting a PopupField in a specific location if it doesn't support uxml. I have my current layout all create initially by the UIBuilder and once I had the basics of it sketched out I just saved and started work with the uxml document and the editor file.

    I had put 4 enum dropdowns but realized one of the fields was best off being a list, but I want it in the 3rd spot of the 4

    How might I get it to layout simialr to this below -

    EnumField
    EnumField
    PopupField
    EnumField

    - if I am using the setup that is generated via the Create menu such as below?

    Code (CSharp):
    1.         public void OnEnable()
    2.         {
    3.             // Each editor window contains a root VisualElement object
    4.             VisualElement root = rootVisualElement;
    5.  
    6.             var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/instance.id/Editor/MyEditor.uxml");
    7.             VisualElement editorLayout = visualTree.CloneTree();
    8.             root.Add(editorLayout);
    9.         }


    Is there some sort of... display dummy or placeholder item? Not sure what to call it. Something that I can tie to an item somehow so that I can put it into the uxml to force a specific item created in C# to display in a particular place in the layout?
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    Code (CSharp):
    1. uxml
    2. <VisualElement name="my-name" />
    3.  
    4. c#
    5. root.Q<VisualElement>("my.name").Add(ne PopupField());
     
  3. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    That worked great, thanks!

    The coded ended up like this in case anyone else needs it later.

    Code (CSharp):
    1.  r.Q<VisualElement>("RootNode").Add(new PopupField<string>("Root Node", choices, 0) { value = "None" });
     
    mcallet_microidslyon likes this.