The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi,
I need to create a dynamic list of images and be able to scroll them.
This is my scene:
ScrollContainer
---> HBoxContainer
------> TextureRect1
------> TextureRect2
------> TextureRect3
------> TextureRect4

It works, but I need the list to be dynamic.

I tried to turn off the visibility of TextureRext4 with this GDScript code: $ScrollContainer/HBoxContainer/TextureRect4.visible = false.
The fourth image disappears but the size of the HBoxContainer still has room for 4 images and not 3.

I tried to resize de HBoxContainer ($ScrollContainer/HBoxContainer.rect_size.x = ...) in according to the number of images but it doesn't work... when I scroll the images I still have the empty space for the fourth image at the end.

How can I do in order to achieve the result I need?
Thank you for your help.

in Engine by (14 points)

1 Answer

0 votes

I'm not entirely sure what you want to happen here. As a test, I replicated your scene tree and adjusted my ScrollContainer width to display 3 of my 4 TextureRects. With that setup, I have a horizontal scrollbar that will let me scroll to see the 4th TextureRect.

Additionally, I added a button to the scene that, when pressed, toggles the visibility of the 4th TextureRect.

The first press of the button hides the 4th item which, in turn, causes the scrollbar of the ScrollContainer to disappear as it's not needed to display the 3 visible items.

Pressing the button again makes the 4th item visible, and the scrollbar returns as it's now needed to see the 4th item.

It almost sounds like you want want the geometry (size) of the ScrollContainer to change to fit its contents, but then you'd never need to "scroll".

Generally, you'd want the container to stay the size you've set it and for it to either have (or not have) a scrollbar to see its full contents. In my above experiment, that's exactly how it works.

by (22,674 points)

Thank you for your reply.

The problem is: if you enable the touch input option (the two Touch input options in Project Settings --- Input Devices --- Pointing), you will see that, even if you toggled the visibility of the 4th TextureRect and the scrollbar of the ScrollContainer disappeared, the Container still has room for the 4th TextureRect and you can scroll to it.

I just want the scroll to be limited to the visible TextureRect.

I don't know if this is the right way to do that, I just need to scroll a list of items but the number of items is dynamic.

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.