Author Topic: Scrolling scroll view with buttons  (Read 15120 times)

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Scrolling scroll view with buttons
« on: May 07, 2012, 07:33:33 PM »
Hi,

I would like to scroll the contents of my scroll view (draggable panel version) using buttons (like a scroll left and scroll right button) instead of using scroll bars. What should the onclick of the buttons modify to do this?

-JJ

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #1 on: May 07, 2012, 09:34:10 PM »
Look into the UIDraggablePanel.SetDragAmount function.

capitalj

  • Jr. Member
  • **
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #2 on: May 07, 2012, 11:53:43 PM »
Yes, I saw that one but it looks more like it will just drag to a specified position.

1. is there a way to read the drag position so that I could just increment it and still use SetDragAmount? Or do I have to create my own var for that?

2. It sounds like the .Drag function would do exactly what I am looking for but it doesn't seem to actually have any effect. I've tried with both setting a Vector2(x,y) and using a Vector2.right

3. With either of these methods is there a way to animate the drag so that it moves the panel as if you used a finger swipe? (so that it doesn't just jump to the new position)

-JJ

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #3 on: May 08, 2012, 11:29:08 AM »
You mentioned that you want to control it purely via buttons instead of the scroll bar, so I assume you don't need to read the drag amount value. Start with 0 in your script, and increment / decrement it with the buttons.

Drag function is your OnDrag event callback, it only works after the drag process started (after Press(true)).

You can interpolate the position using the SetDragAmount method I suggested. Just interpolate your value before passing it to the function.

krubba1

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #4 on: October 19, 2012, 02:13:04 PM »
I'm trying to the same thing, using SetDragAmount to some value between 0 and 1, and it is moving the clipped area around rather than the contents. I'm sure I must be missing something obvious, but am quite new to NGUI. Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #5 on: October 19, 2012, 02:50:00 PM »
That's how dragging works -- clipped area is moved, while the contents stay in place. This way the buffers don't need to be rebuilt while dragging the UI, resulting in better performance. From the game's perspective it should work exactly as you expect with the window's contents moving properly.

krubba1

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #6 on: October 19, 2012, 02:57:57 PM »
I'm confused, if the clipped area moves and contents stay still, wouldn't the clipped area eventually be off screen? Is the camera supposed to follow the clipped area?

After playing around, I found that if I remove this 'if' condition inside SetDragAmount, it seems to work fine.

Quote
      
      if (!updateScrollbars)
      {
         Vector3 pos = mTrans.localPosition;
         if (scale.x != 0f) pos.x += cr.x - ox;
         if (scale.y != 0f) pos.y += cr.y - oy;
         mTrans.localPosition = pos;
         Debug.Log ("Drag Position x: "+x +", y: "+y+", to : "+mTrans.localPosition);
      }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #7 on: October 19, 2012, 03:02:10 PM »
Camera? What does camera have to do with it? Draggable panel script works with shader-based clipping. Camera-based clipping is an entirely different beast.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #8 on: October 19, 2012, 04:55:19 PM »
Krubba, your clipped area moves and the draggable panel's local position moves opposite to it.

krubba1

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #9 on: October 19, 2012, 05:33:34 PM »
clipped area and panel moving opposite to each other kind of makes sense to me i think, but if i look at the code in SetDragAmount, the only place the panel is moved is inside that "if" statement. I was passing in updateScrollbars = true (since i don't know why you wouldn't update scrollbars, so the if statement was skipped, and only the clipped area moves, not the panel itself.

Not sure why the panel wouldn't be moved if updateScrollbars is passed in as true....

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scrolling scroll view with buttons
« Reply #10 on: October 20, 2012, 12:16:09 AM »
Because if you have scroll bars, you should move the panel via those scroll bars. It's not a very elegant solution, but it's there to prevent fighting of different components. Scroll bars have higher authority, and handle things slightly differently.