Author Topic: Diverse problems with a dynamically modified UIScrollView  (Read 4004 times)

pdelaossa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Diverse problems with a dynamically modified UIScrollView
« on: August 12, 2014, 05:03:04 AM »
Hi. First of all, thank you for NGUI.

I'm having three different problems within the same game object structure. Said structure is as follows:

+ PanelDescription   <-- UIPanel with a lateral tweening
   + Scroll              <-- UIPanel with a vertical UIScrollView
      + Text1           <-- UIWidgets with child UILabel and UISprites
      + Text2
      + Text3

Being its intended behaviour:
- The whole panel is usually hidden. Under certain conditions, it is shown or hidden with the tweening.
- The scroll must be on a panel because we want vertical 'softening' and clipping.
- The number of Text objects inside the scrollview will vary dynamically.

I'm not using UIGrid because I have objects of varying sizes that stack on the bottom of each other.

Each time I want to add or remove a Text object I first clean the scrollview, repositioning it with UIScrollView.ResetPosition() before and after the cleanse.
After I repopulate it, I ResetPosition again just in case.

And regarding the scrolling itself: I tried both using a single invisible collider that anchors to the first and last Text object, and making each Text object a drag scrollview collider itself.

Oh, and the lateral tweening of PanelDescription is being done by a TweenAnchor I made myself to tween directly with the anchors.
Now, with the problems:
1st) The scrollview NEVER begins at its correct, topmost, position. Even when the content origin is set as TopLeft.
2nd) The scrollview automatically moves up when the father PanelFormulas is tweening. Even if it is at its bottom. I must say that I made sure, and even more it has absolutely no sense, that the tweening itself is somehow directly affecting the scrollview. This correlation (or maybe causation) has to be caused indirectly.
3nd) The scrollview movement itself is flawed: When dragging a dragscrollview object after we are in a boundary I can move outside the boundaries. If we are not yet on a boundary, then it stops properly.

Both the first and third problem can only seem to be "solved" (more like patched) setting the Y position manually in the transform of the Scroll object. However this Y position changes each repopulation, thus making this not even a patch.

I've been looking for a while for any of these 3 problems in these forums but couldn't find it solved. I'm sorry if any of them are.


Thank you for your attention, and I hope I didn't miss any key information and that I made myself clear.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Diverse problems with a dynamically modified UIScrollView
« Reply #1 on: August 12, 2014, 07:15:28 AM »
3. The option to prevent moving if the content fits is specified on the scroll view (cancel drag if fits). However if the content doesn't fit (like it starts outside), then you will still be able to move it.

2. Not sure about this one.

1. Creating content doesn't immediately add it to the managing panels. This process is delayed, so assuming you instantiate content and then try to reset the scroll view, doing so will do nothing. You can force widgets to be added by calling CreatePanel() (you can just broadcast it).

pdelaossa

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Diverse problems with a dynamically modified UIScrollView
« Reply #2 on: August 18, 2014, 03:14:36 AM »
Thank you very much for the steady and concise answer.


Quote
1. Creating content doesn't immediately add it to the managing panels. This process is delayed, so assuming you instantiate content and then try to reset the scroll view, doing so will do nothing. You can force widgets to be added by calling CreatePanel() (you can just broadcast it).

I'm not really sure what are you referring to with broadcast (most likely because of limited C# knowledge). In any case, reading the code of CreatePanel I see that what you do is look for a panel and force/assign it to the widget. It works, with a patch.

I must wait a handful of frames. Is there any other way other than forcing such a wait to reset the position? I can add a tweenalpha or something to disguise it, but that is nonetheless a patch.

Also, should I care about what panel is being picked and take precautions? or can I shamelessly use this method for all the widgets in each of these structures with no downsides?


Quote
2. Not sure about this one.
Actually, it was a byproduct of one of the other 2 problems. It's not happening anymore.


Quote
3. The option to prevent moving if the content fits is specified on the scroll view (cancel drag if fits). However if the content doesn't fit (like it starts outside), then you will still be able to move it.
That option has always been ticked, because it's the behaviour I obviously want.

I found that I explained myself very poorly, but I'm not going to rephrase it because I found more precise details about what was causing the strange behaviour: a ScrollBar.

If I just remove the scrollbar, this problem is solved and I cannot move outside the scrollview boundaries. As for now, I'm just not going to use the ScrollBars and work on the other two problems. If, in a future, I happen to encounter this again, I'll ask here with more details.



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Diverse problems with a dynamically modified UIScrollView
« Reply #3 on: August 18, 2014, 11:56:13 AM »
instantiatedGameObject.BroadcastMessage("CreatePanel");