Author Topic: UIDragScrollView misplacing children  (Read 5462 times)

loptrinho

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
UIDragScrollView misplacing children
« on: June 26, 2016, 06:26:22 AM »
Ok, I've spent quite an amount on this now and it's driving me nuts...

Searching the forum didn't yield useful results (unless I'm blind - what's well possible^^)

I have a UIDragScrollView containing a ScrollView with a list of buttons (sort of class selector for an rpg). My problem is as follows:

This menu-like scroller is part of a multi-step process and should initially be hidden (like the other steps, it's all managed) and only be shown when its turn has come. But no matter what I do, the buttons are totally misplaced if the whole section isn't initially visible (cf. screenshots).
  • I have already tried various setups of UIDragScrollView and ScrollView along with different UI elements, to no avail.
  • I have also tried different update options for the different UI elements (because I thought I could've misconfigured them in my attempt to reduce update calls) - same result.
  • The button list is placed on an invisible widget that is anchored to the left (I wanted to use a panel, but it couldn't be anchored and my various attempts with panels resulted in the same misplacing...).
I've got the feeling that I'm missing something really obvious here, but I just don't get it :(

Any help would be greatly appreciated.

NGUI v3.9.9

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragScrollView misplacing children
« Reply #1 on: June 27, 2016, 06:39:53 AM »
Buttons are under an anchored widget? I'm assuming the widget is then inside the scroll view? That's what you're doing wrong. The anchored element needs to be outside the scroll view. Take a widget, anchor it, then add a scroll view underneath it.

loptrinho

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIDragScrollView misplacing children
« Reply #2 on: June 27, 2016, 06:55:47 AM »
As far as I can tell, the anchored widget is the scrollView's parent.

But looking through my scene (gathering further information for this response) I discovered an anchored panel as well (cf. panel.jpg). Maybe that's the issue? I thought I had taken the structure from the scrollview example scene, but it might be that I messed it up...

Find attached some screenshots of the critical parts.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragScrollView misplacing children
« Reply #3 on: June 27, 2016, 06:59:32 AM »
Buttons are also anchored? I'd say that's the problem right there. Also you should keep the "Execute" field consistent. Start or enable, not mix and match. Update is also a good choice. The only thing anchored in there should be the widget, anchored to the root or camera. If you need the scroll view to adjust its size, anchor that to the widget parent.

loptrinho

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIDragScrollView misplacing children
« Reply #4 on: June 27, 2016, 07:07:03 AM »
As far as I can tell buttons are not anchored (cf. screenshot), but added at runtime from the prefab.
But I'll try out your suggestions and keep practicing (after work) ;)

btw: I understand that anchors with "Update" option are realigned with each "Update" call, i.e. every single frame? Doesn't this have an impact on performance?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragScrollView misplacing children
« Reply #5 on: June 27, 2016, 07:08:16 AM »
I meant your "Discipline Buttons" game object. Reducing the number of anchored objects should help.

"Update" will affect performance, yes -- but if you only have 2 widgets anchored like I suggested, then it's hardly worth worrying about.

loptrinho

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIDragScrollView misplacing children
« Reply #6 on: June 27, 2016, 07:16:02 AM »
I understood anchors as the major means to create self-adjusting layouts.
If I am wrong, I'am afraid I'll need some advice on how to do it in another way.

Anyway, I'm not sure if I'm getting what you are trying to teach me, but I'll have a closer look later...

[EDIT]I do not quite understand how the suggestions you made make a difference between initially enabled game object and later enabling[/EDIT]

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragScrollView misplacing children
« Reply #7 on: June 28, 2016, 09:22:50 AM »
The important part is to not anchor anything inside your scroll view, that's all. Just try it.