Search Unity

Question Can I make a custom ScrollView in UI Toolkit

Discussion in 'UI Toolkit' started by mulinmulin, Aug 26, 2020.

  1. mulinmulin

    mulinmulin

    Joined:
    Aug 26, 2020
    Posts:
    4
  2. guodan

    guodan

    Joined:
    Dec 22, 2016
    Posts:
    29
    upload_2020-8-26_18-35-1.png

    The ListView demo shows: it will recycle item. Is this your foucs on "few ui items"?
     
    mulinmulin likes this.
  3. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Yes, the goal of the ListView is to create as few elements as possible to fit the visible area of a scroll view.

    In general you do need to inherit from ListView, you just configure it with the required callbacks.
     
    mulinmulin likes this.
  4. mulinmulin

    mulinmulin

    Joined:
    Aug 26, 2020
    Posts:
    4
    Yes, that's the function what I need.
    I used to add VisualElement into list directly but not bind data on it. Now I'm learning it. Quite confusing..
     
  5. mulinmulin

    mulinmulin

    Joined:
    Aug 26, 2020
    Posts:
    4
    Hello, I finally figured out how to use ListView and bind data on it. And I want it works as grid in UGUI.
    I bind a two-dimensional array on ListView and it works fine. I don't want its default hang over and selected effect style, how could I change it or is my direction correct?

    Thanks.
     
  6. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    You can change the style of the ListView by overriding the default style with your own USS file.
    To get started have a look at the elements you want to change in the UI Toolkit debugger, look at their USS classes and override them in your USS file.

    User defined styles always take precedence over default one so you can totally change the look with this approach.
     
  7. mulinmulin

    mulinmulin

    Joined:
    Aug 26, 2020
    Posts:
    4
    Made it! Great thanks to you!