Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UIElements ListView

Discussion in 'UI Toolkit' started by SureSight, Aug 1, 2018.

  1. SureSight

    SureSight

    Joined:
    Aug 2, 2013
    Posts:
    65
    I am experimenting with adding a scrollable list view that handles to selected items to update another VisualElement (Master/Detail view).

    I'd appreciate a crude example of how to implement a ListView with reorderable list items.

    Bonus points for showing how the binding system works :)
     
  2. SureSight

    SureSight

    Joined:
    Aug 2, 2013
    Posts:
    65
    I believe I am most of the way there, but the height of the ListView seems to remain 0 even after applying styles

    Code (CSharp):
    1. VisualElement root = this.GetRootVisualContainer();
    2.         root.AddStyleSheetPath("characterEditor");
    3.  
    4. IList list = new[] { "Joe", "Larry", "Richard" };
    5.  
    6.         ListView listViewCharacters = new ListView(list, 20, () =>
    7.         {
    8.             VisualContainer container = new VisualContainer();
    9.             container.focusIndex = 0;
    10.             container.AddToClassList("listViewItem");
    11.  
    12.             Label newLabel = new Label();
    13.             container.Add(newLabel);
    14.  
    15.             return container;
    16.         },
    17.             (VisualElement element, int index) => {
    18.                 VisualContainer container = ((VisualContainer)element);
    19.                 Label label = (Label)container.ElementAt(0);
    20.  
    21.                 label.text = (string)list[index];
    22.             });
    23.  
    24.         listViewCharacters.AddToClassList("listView");
    25.         listViewCharacters.onSelectionChanged += OnCharacterSelectionChanged;
    26.         root.Add(listViewCharacters);
     
  3. Parabol83

    Parabol83

    Joined:
    Nov 19, 2013
    Posts:
    6
    You need to set itemHeight on the list view as well. I have noticed a few issues with the list view in 2018.2 however. Currently onSelectionChanged returns a list of null objects, and the width of list items is not updated when the scroll bar becomes active.
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Here's a basic List example that is more practical than the default ones.

    The included examples manipulate the UI Elements themselves, which is relatively useless. Ideally the loop is to have the UI Elements update serialized data, then refresh automatically when that data changes which prompts the changes in the UI Elements themselves.

    I mashed up concepts from several examples to edit some Asset files (Items) in the project with very primitive default PropertyField inspectors. I would consider this a practical barebone example to get started with something like an Inventory System.

    Overall I have a lot of issues with the new API at this point.
    • It feels incomplete and too abstract. I suppose it's still experimental and expectedly little high level support at this point.
    • Binding UIE's to data is unclear and difficult.
    • Small style errors often result in the UI not even appearing, and it's not clear why.
    • What would seem like a good way to access something doesn't exist, and the correct path or method is named strangely or placed in some other class.
    • Descriptions on methods/properties are often too vague to understand.
    • The serialization example doesn't retain changes.
    While it does seem like it will probably get there eventually and the abstraction is useful, there's a lot of stuff that needs to improve before it leaves Experimental and offers a 1:1 replacement for IMGUI custom editors.
     

    Attached Files:

    Lahcene likes this.
  5. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Thanks for the feedback! If I may, can I ask for some examples to go with your points/issues above? Some specifics here would be helpful.

    For example: "What would seem like a good way to access something doesn't exist". What specifically did you try to access that was not possible or too difficult?
     
  6. benoitd_unity

    benoitd_unity

    Unity Technologies

    Joined:
    Jan 2, 2018
    Posts:
    331
    FYI, we now have a dedicated sub-forums where you can use for all your questions and feedback related to UI Systems Previews.

    Cheers,
     
    LaneFox likes this.
  7. pokelocos

    pokelocos

    Joined:
    Nov 9, 2015
    Posts:
    54
    Here's the updated package, version 2022.1.13, with some bug fixes that were caused by outdated dependencies. I'm not sure if anyone will find this useful, but I figured it's better to share it tan not.
     

    Attached Files:

    LaneFox likes this.