Search Unity

Bug [SOLVED] ScrollView does not render well out of the box

Discussion in 'UI Toolkit' started by aybeone, Feb 4, 2019.

  1. aybeone

    aybeone

    Joined:
    May 24, 2015
    Posts:
    107
    When you add a scroll view using defaults you get the following:

    Unity_2019-02-04_20-19-28.png

    Code (CSharp):
    1.  
    2. .thumbnails {
    3.     flex-grow: 1;
    4.     flex-direction: row;
    5.     flex-wrap: wrap;
    6. }
    Code (CSharp):
    1.   <engine:ScrollView name="ScrollView">
    2.     <engine:VisualElement name="Thumbnails" class="thumbnails">
    3.       <engine:Box style="width:128; height: 128" />
    4.       <engine:Box style="width:128; height: 128" />
    5.       <engine:Box style="width:128; height: 128" />
    6.       <engine:Box style="width:128; height: 128" />
    7.       <engine:Box style="width:128; height: 128" />
    8.       <engine:Box style="width:128; height: 128" />
    9.       <engine:Box style="width:128; height: 128" />
    10.     </engine:VisualElement>
    11.   </engine:ScrollView>
    It's only when you hack it with the following that you finally get something correct:

    Unity_2019-02-04_20-19-55.png

    Code (CSharp):
    1.             var view = tree.Q<ScrollView>("ScrollView");
    2.             var scroller = view.verticalScroller;
    3.             var scrollerSlider = scroller.slider;
    4.             scrollerSlider.style.width = 15;
    5.             scrollerSlider[0][1].style.left = -5;
    Somehow the initial width is 70 which is definitely the problem.

    Now while it looks correct there's a huge problem, if you don't leave your mouse precisely within the slider it stops scrolling; I guess this value of 70 is intentional for good UX but somehow it's not working out of the box.

    Are you aware of the problem ?
     
    Last edited: Feb 4, 2019
  2. aybeone

    aybeone

    Joined:
    May 24, 2015
    Posts:
    107
    Here's another approach that really fixes the problem, now you don't have to be precisely inside the scroller to scroll :).

    Code (CSharp):
    1.             var view = tree.Q<ScrollView>("ScrollView");
    2.             view.style.marginRight = -55;
    3.             view.verticalScroller.slider.style.paddingLeft = 0;
    4.             view.verticalScroller.slider.style.unitySliceLeft = 14;
     
  3. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    It's best to report bugs using our bug reporting tool. That way they can be properly tracked. The forum is more for questions and discussions. But this does appear like a bug. Which version of Unity are you using?
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This looks like you're still using the Experimental UIElements api. A lot of problems around ScrollView have been fixed in 2019.1. Please upgrade. The Experimental API is not supported. :)
     
  5. aybeone

    aybeone

    Joined:
    May 24, 2015
    Posts:
    107
    Using 2019.1.0b1 and non experimental controls, going to report it but actually I'm having really weird issues and trying to find the cause, even the simplest example exhibits that behavior:

    Unity_2019-02-04_23-03-38.png

    Note, it was working fine then suddenly the slider changed to this :mad:.
     
  6. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Hmm, try updating to 2019.1.0b2? If not, bug report will be best.
     
  7. aybeone

    aybeone

    Joined:
    May 24, 2015
    Posts:
    107
    Well ... going to update ASAP ... in the mean time I've fixed it, something really dumb from me, I was overriding Slider style directly in the USS, lesson learned :D.

    Unity_2019-02-04_23-15-03.png
     
  8. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Yep! Always best to assign your own classes and match by class, instead of using the C# types or built-in element names.
     
  9. aybeone

    aybeone

    Joined:
    May 24, 2015
    Posts:
    107
    I was already going to blame Unity :rolleyes:!