+11 votes

I want to make an inventory list that can be scrolled up and down. I have a ScrollContainer, and I've tried adding some Panel children to it, but they are always set to position (0,0). How do I properly add children to the ScrollContainer to make a list?

in Engine by (676 points)

1 Answer

+20 votes
Best answer

You add a Node Scrollcontainer, then add a Child Node ( VBoxContainer for vertical or HBoxContainer for horizontal listing) to the ScrollContainer.
Set the Separation of the VBoxContainer (or HBoxContainer) to the value (in pixels) you want the objects to be Separated.
After that you can add child nodes to the V(H)BoxContainer and you are done.
NOTE1 that for the child notes to be listed those nodes must be Control nodes. For example if you want to have a scrolling list of Buttons the Child Node must look like this :
The reason is, if I understand it correctly, that the V(H)BoxContainer will automatically change the position of the Control nodes to fit the Separation value.
Note2 The last child of the V(H)Boxcontainer may not be listed, for reasons unknown to me, the easy way to bypass this is to add a Control node as the last Child Node.

by (177 points)
selected by

Thank you, this worked!

In 2.1-dev I'm unable to reproduce note1 and note2 :)

Bojidar I haven't tried the current dev version, I am using the latest 2.0.1 release. But your problem probably is that you haven't changed the Rect size of the ScrollContainer.

I created a simple example, check it out : https://github.com/kakoeimon/Godot_ScrollContainer_Example

I can't find the "Separation" member for the H(V)BoxContainer in the documentation or Godotengine editor.
Can you give a link to its API?

Yes, the documentation is empty : http://docs.godotengine.org/en/latest/classes/class_hboxcontainer.html?highlight=hboxcontainer
Separation is under the params tab of the selected node. Default 2.0.1 to the right. You know the tab where you can change anchor, margin, rect and etc.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.