Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

[Ui Builder] How do I add items to a list view?

Discussion in 'UI Toolkit' started by WizByteGames, Apr 8, 2020.

  1. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    I just downloaded UI Builder. Wanted to see how it would help with quick editor window building. I don't see a way to add items to a list view at all. I can't even parent items to it. Am I missing something or do you have to do it only from code?
     
  2. DonkeyPotato

    DonkeyPotato

    Joined:
    Mar 23, 2018
    Posts:
    28
    Populating a ListView is pretty code driven. You can set the data source (the bind-path field I believe) in the UI Builder, but you'll still have to setup the corresponding SerializedObject in code, and write code to create and bind the individual items as the ListView scrolls.

    It's purpose is to support scrolling through large amounts of homogenous data in an efficient manner. It does this via 'virtualized' scrolling. What that means is that it only creates the number of UI items that can be visible at any one time, given the dimensions of the ListView. As you scroll through the content and an item moves outside the visible portion of the ListView, it 'recycles' it, and moves it to the top or bottom of the visible area (depending on what direction your scrolling), and binds the item to the appropriate piece of data.

    So, as you can see (hopefully), it's not possible to just add whatever random content you want to it in the editor.
     
    gareth_untether likes this.
  3. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    If you have a static list of items and don't need the pooling/recycling of elements when scrolling, you can use a ScrollView directly.
     
    m_craig36 and marcospgp like this.
  4. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    Ah I see, I was only going to use it to see what temporary data looked like in the list so I could format it properly. I'm so use to doing it that way with UGUI that I just assumed that it worked that way.

    But thanks for the info so next time I know what to expect.
     
  5. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    OK I'm a bit confused. I was using a scroll view in another part of the editor I'm making and I tried dragging a visual element onto the container for the scroll view and nothing happened. But when I tried to parent the element to the scroll view directly it put it in the container for me. So I did that same thing with the list view and it worked. Not sure if everyone knows this. But I think that should be more clear for people who are just starting out with UI Builder as I am.
     
  6. Akidamaru

    Akidamaru

    Joined:
    Sep 8, 2015
    Posts:
    7
    I found a way to add a visual element in the container of a scroll view from the UIBuilder:

    You can do this:
    • Add your ScrollView in the UIBuilder
    • Open the .uxml with a text editor and find the <ui:ScrollView ... /> part
    • Add something like a label as a child of the ScrollView this way upload_2023-3-29_10-42-19.png
    • Now you will see a label inside the container
    • Now you can add more elements as siblings of that Label, or child, etc... and remove the Label later

    I hope this helps

    ###EDIT###

    Yes, as said on the post before this you can just drag your element on the ScrollView/ListView/Etc. element and it will get automatically put as child of the container
     

    Attached Files:

    Last edited: Mar 30, 2023