Author Topic: UIScrollView and UIScrollBar questions  (Read 21982 times)

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
UIScrollView and UIScrollBar questions
« on: July 25, 2015, 06:24:49 AM »
Got everything working how it should recently (which is a feat for me), but I have a couple of questions...

1.  Is there a way to tell if the scrollbar is showing for a particular scrollview?  I want to allow the player to move the scrollbar via keyboard or controller, but I don't want to move anything if there isn't a scrollbar at all.

2.  For some reason my scrollbars aren't working at all with a mouse.  I have them setup just like they are in the demo however they won't move via mouse at all.  I turned on debugging and it shows that the "Last Hit" is the scrollbar area, but it refuses to work.  Not sure what's going on, but perhaps someone can shed some light on this for me.  (Note: I can move it manually via code, but the mouse functions don't seem to be working.)

3.  Does the thumb of a scrollbar need to have a drag script attached for it to work?

Any information provided would be most helpful.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #1 on: July 27, 2015, 08:16:03 PM »
1. Controllers don't work with scroll bars. Generally when you have something selected with a controller that happens to be inside a scroll view, its UIDragScrollView script will handle controller-based scrolling automatically. Check your UICamera -- you need to have the Pan axes set (usually to the right thumbstick).

2. Did you forget to link it with your scroll view? Check your UIScrollView script. Also note that you may simply have the background of the scroll bar in front of the foreground, or just forgot to add a collider to the foreground altogether.

3. No.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #2 on: July 29, 2015, 09:05:53 AM »
1. Controllers don't work with scroll bars. Generally when you have something selected with a controller that happens to be inside a scroll view, its UIDragScrollView script will handle controller-based scrolling automatically. Check your UICamera -- you need to have the Pan axes set (usually to the right thumbstick).

I got it working by handling it by code.  Is there a way to find out if the scrollbar is showing?  For each item on the list, I want to check to see if the scrollbar is showing before I allow it to be moved.  However, I haven't found out a way to tell if it's showing for a particular block of text.

Quote
2. Did you forget to link it with your scroll view? Check your UIScrollView script. Also note that you may simply have the background of the scroll bar in front of the foreground, or just forgot to add a collider to the foreground altogether.

Does the functionality have to be on the foreground?  At the moment my foreground has nothing attached to it since I have a thumb object.

Also, as a side note, I have a problem with one of my selector objects not animating anymore.  I have a selector that goes down the list using TweenPosition.  Whenever the player presses down or up, it calls TweenPosition with the new location.  The crazy thing is that the animation fires, but it doesn't actually move.  So the position gets updated, but the graphic stays in the same place.  Does this have anything to do with being inside a scrollview area?  It used to work, but since updating it doesn't anymore.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #3 on: July 31, 2015, 09:38:41 PM »
Scroll bar showing? Just check its alpha. If it's 0, then it's not showing.

When in doubt, look at the controls that come with NGUI. Both the background and the foreground need to be linked to the UIScrollBar as "Background" and "Foreground" fields.

Check your panel. If you turned on its static flag, then there should be a warning on it explaining to you that moving widgets underneath the panel will have no effect. That said, why are you using TweenPosition? If you have it linked as a scroll bar, when you start dragging it, the scroll bar's logic takes control of it, and your tween position won't work, as the two of them will fight for control of its position.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #4 on: August 01, 2015, 01:14:57 PM »
Scroll bar showing? Just check its alpha. If it's 0, then it's not showing.

Is there a way to force it to check to see if a scrollbar is needed for each element in a list?

Quote
When in doubt, look at the controls that come with NGUI. Both the background and the foreground need to be linked to the UIScrollBar as "Background" and "Foreground" fields.

I checked, but I didn't see any with a thumb object.  I'll just use a foreground and a background from now on.

Quote
Check your panel. If you turned on its static flag, then there should be a warning on it explaining to you that moving widgets underneath the panel will have no effect. That said, why are you using TweenPosition? If you have it linked as a scroll bar, when you start dragging it, the scroll bar's logic takes control of it, and your tween position won't work, as the two of them will fight for control of its position.

Awesome.  This was the problem.  I didn't realize that the objects underneath would also be blocked from moving.  This last question was related to a different window.  That window has a cursor that moves up and down a list which allows the player to select an option.

Another question related to the issue above.  If I have along list of options that are setup in a scrollview window.  What would be the best way to scroll through the list?  Right now, I am simply redrawing the list moving the starting point on the list every time the player moves the cursor down (or up).  I feel like there should be a better way to do this.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #5 on: August 05, 2015, 07:42:57 AM »
I don't understand what you mean by your first question. Scroll bar for each element in a list?

I am also not quite clear on the last part... what do you mean by redrawing the list moving the starting point every time the player moves the cursor up or down? Why do you need to do any of this? NGUI handles scrolling via UIDragScrollView, either using the mouse, touch, scroll wheel or controller.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #6 on: August 05, 2015, 11:32:05 AM »
I don't understand what you mean by your first question. Scroll bar for each element in a list?

I think it's better to provide a screenshot....

Quote

What I mean is that on left you can see the name of the quest.  On the right there's the description of the quest.  The length of each quest description will vary, and thus doesn't need to have a scrollbar shown.  I want to be able to test to see if the each description needs a scrollbar and show it accordingly.  No point in having a scrollbar if the description is short.

Quote
I am also not quite clear on the last part... what do you mean by redrawing the list moving the starting point every time the player moves the cursor up or down? Why do you need to do any of this? NGUI handles scrolling via UIDragScrollView, either using the mouse, touch, scroll wheel or controller.

The other question was related to the list on the left.  As this list gets longer, not all quests will fit in the window.  This is why I changed it to a scroll window.  However, I'm wondering what the best way to handle moving the list up and down (manually) as the player scrolls up or down through the list?  To be honest, I don't have enough quests in the game right now to fill that list, but at some point in the near future I will.

Maybe I couldn't think of the best way to describe it, but I hope that seeing what I have going on will make it clearer.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #7 on: August 08, 2015, 11:07:38 PM »
NGUI has an option to that on the scroll view script. Hiding the scroll bar if it's not needed is one of the options.

"best way to handle moving the list up and down (manually) as the player scrolls up or down through the list" <-- this also doesn't make much sense. Why do you want to handle moving the list up and down? Scrolling will already do it for you. You don't need to do anything. That's the whole point of having a scroll view, no?

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #8 on: August 09, 2015, 08:22:30 AM »
NGUI has an option to that on the scroll view script. Hiding the scroll bar if it's not needed is one of the options.

Which option is that?


Quote
"best way to handle moving the list up and down (manually) as the player scrolls up or down through the list" <-- this also doesn't make much sense. Why do you want to handle moving the list up and down? Scrolling will already do it for you. You don't need to do anything. That's the whole point of having a scroll view, no?

I move all windows and lists by keyboard and controller.  Some can be moved with the mouse as well.  I have never been able to get keyboard/controller functionality working without doing it manually.  Which I don't mind doing, but I just need to know what functions move windows and things manually.  At the moment, moving down the list with the up/down arrow and the d-pad works great.  I just want to be able to scroll the window manually (pressing down or up will move the window X number of units or to the next item on the list).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #9 on: August 14, 2015, 08:08:01 AM »
Did you set the Pan axes on the UICamera? That's what's used to scroll using the controller. Generally you'll use the left thumbstick or D-Pad for navigation and right thumbstick to scroll/pan. Default Unity project sets Horizontal and Vertical axes to the left thumbstick, but the right one remains undefined. See this topic for more info: http://www.tasharen.com/forum/index.php?topic=13047.0

As for hiding the scroll bar, select the UIScrollView script and underneath the "Scroll Bars" section there is a "Show Condition" field. Set it to "Only if needed".
« Last Edit: August 14, 2015, 09:59:02 AM by ArenMook »

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #10 on: August 14, 2015, 08:34:46 AM »
Did you set the Pan axes on the UICamera? That's what's used to scroll using the controller. Generally you'll use the left thuymbstick or D-Pad for navigation and right thumbstick to scroll/pan. Default Unity project sets Horizontal and Vertical axes to the left thumbstick, but the right one remains undefined. See this topic for more info: http://www.tasharen.com/forum/index.php?topic=13047.0

It doesn't work for all controllers on all systems.  Again, this is fine, I don't mind doing this stuff manually, just need to get the scrolling working.  I think there should be a way to interact with all widgets manually for those who want to go that way.  Just need to know how I can scroll the window up or down manually....


Quote
As for hiding the scroll bar, select the UIScrollView script and underneath the "Scroll Bars" section there is a "Show Condition" field. Set it to "Only if needed".

Yep.  I have this set.  The issue is that if it becomes active, it will stay active even if "Only if needed" is checked.  I thought that if I could refresh the scroll area every time the player moves to a new quest on the list that it would reset the scrollbar.  Unfortunately it doesn't.  That's why I asked if there was a way to force the system to check if the current quest text needed a scrollbar.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #11 on: August 14, 2015, 10:07:51 AM »
You are correct in saying that it doesn't work for all controllers / systems. That's because every controller has a completely different button layout. There is no standard between them, which is why a plugin like InControl is so useful to have. It takes care of that for you.

To do it manually, have a look at how panning works in UICamera. Just open UICamera and search for "OnPan". You'll notice that it simply sends pan messages to the targeted object every update with the delta. Now check UIDragScrollView script, line 129 (the OnPan function). See how it forwards the OnPan event to the actual scroll view? The scroll view then does the panning.

The scroll bar hiding is done by UIScrollView as well, in the LateUpdate function. Note line 915:
  1.                         if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
  2.                         {
  3.                                 vertical = shouldMoveVertically;
  4.                                 horizontal = shouldMoveHorizontally;
  5.                         }
That code checks to see if the scroll bars should be visible, and the alpha of the scroll bars is set right below that.

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: UIScrollView and UIScrollBar questions
« Reply #12 on: August 18, 2015, 11:50:32 AM »
Cool.  Thanks for the information.  I'll see what I can do with the information.

Just to be clear, I use InControl as well.  However, I'm working on the Wii U and that's not supported by InControl.  So everything has to be done in a way that works for that system which means most GUI things have to be done manually.  98% of everything I have so far works great.  Just a couple little details that need to be ironed out.  Hopefully I can do that this weekend.  :D