Author Topic: Scrollbar Issue  (Read 7489 times)

Matthias

  • Guest
Scrollbar Issue
« on: April 24, 2012, 06:01:11 PM »
I have made a horizontal draggable panel with a scrollbar on a 3D panel that works fine.

I copied that entire rig, changed its format and made it a vertical draggable panel by setting the UITable columns to 1 and using a vertical instead of a horizontal scrollbar.

When I drag the scrollbar with the mouse, the thumb moves at about twice the speed as the mouse and I cannot figure out why. I unified all scales and rotations and it still happens.

Interestingly enough it happens on occasion, but very seldom, with the horizontal setup as well, but it seems to fix itself once I mess with something else in the scene.

Any suggestions how to track this down without having to understand all the scrollbar code?

Thanks

Matthias

  • Guest
Re: Scrollbar Issue
« Reply #1 on: April 24, 2012, 06:30:25 PM »
While we're at this topic I figured I add some code regarding a related question and perhaps something that affects the previously stated problem.

I wrote a function to force the thumb of the scrollbar to be restored to a certain location after I remove and re-add all the list items. After some experimentation I came up with the following, but it does not work correctly, with every update the bar doesn't go back but moves to a bit higher value (that is unless it is a 0 or at max).

What is the clean way to force a full update of the scrollbar and setting its positon?

        void UpdateScrollBar( float desiredscrollvalue )
    {
        UIDraggablePanel dragpanel = mPanel.GetComponent<UIDraggablePanel>();
        dragpanel.ResetPosition();
        dragpanel.UpdateScrollbars(true);

        dragpanel.horizontalScrollBar.scrollValue = desiredscrollvalue;

        UITable table = mClothingItemDragDropContainer.GetComponent<UITable>();
        if (table != null) table.repositionNow = true;
    }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollbar Issue
« Reply #2 on: April 24, 2012, 11:46:59 PM »
Make sure you're referencing the right slider on the drag panel -- horizontal and vertical are different values after all.

To reset the scroll position of a draggable panel, set its "relativePositionOnReset" then call ResetPosition(). RelativePositionOnReset values are 0-1 range: (0, 0) means top-left corner, (1, 1) means bottom-right.

Matthias

  • Guest
Re: Scrollbar Issue
« Reply #3 on: April 25, 2012, 11:02:11 PM »
This took quite a bit more experimenting to get this to work and there is still some real ugly behavior.

This is the process now. The script that's doing this needs to be at the end of the script order because it is depending on the Reposition() in UITable.LateUpdate() being done before the panel.ResetPosition():

In Update():
UITable table = mDragDropContainer.GetComponent<UITable>();
table.repositionNow = true;


In LateUpdate():
panel.relativePositionOnReset = new Vector2( desiredHorizValue, desiredVertValue );
panel.ResetPosition();


The ugly part is that every time I do this after the contents of the UITable changes, the position of the UIDraggablePanel that it is contained in wanders off (literally). After many updates the panel with its Box Collider has moved far, far away. So I still need to hack something in to bring the panel back.

Perhaps something could be build in to address this? I frequently change the contents of my draggable panels and have to rely on this working properly.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollbar Issue
« Reply #4 on: April 25, 2012, 11:07:29 PM »
Try changing late update to:

  1. panel.relativePositionOnReset = Vector2.zero;
  2. panel.ResetPosition();
  3.  
  4. panel.relativePositionOnReset = new Vector2( desiredHorizValue, desiredVertValue );
  5. panel.ResetPosition();
« Last Edit: April 25, 2012, 11:09:49 PM by ArenMook »

Matthias

  • Guest
Re: Scrollbar Issue
« Reply #5 on: April 25, 2012, 11:46:04 PM »
That helped a little but it still bounced around, away from its original position.

I noticed though that when I made sure the value of the unused axis is always 0, it stays put. If it's 1 for example, it wanders off. This came up as I made a (vertically scrollable) panel that is wider than its content items and I tried to center them with the horizontal scroll value. I won't do that again, keeping it at 0...

Thanks,
Matthias

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrollbar Issue
« Reply #6 on: April 26, 2012, 12:04:45 AM »
Random thought... what about:

  1. panel.ResetPosition();
  2. panel.relativePositionOnReset = new Vector2( desiredHorizValue, desiredVertValue );
  3. panel.ResetPosition();