How do I find the max value of scroll_horizontal in a scrollContainer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PeterA

Hello everyone,

I am trying to move text with a Tween Left and Right by scrolling Horizontally in a scroll container.

The scrolling is hanlded by a tween node like so:

tween.interpolate_property(self,'scroll_horizontal',min_value,max_value,10.0,Tween.TRANS_LINEAR,Tween.EASE_IN_OUT)

The problem is that different texts require more or less scrolling, so the maximum value of the scroll_horizontal changes dynamically.

That’s good and all, but I can’t find that value to use it in the tween.

Any idea where or how to find it?

:bust_in_silhouette: Reply From: PeterA

Answering my own question in case anyone needs it in the future:

The max value of scroll horizontal in a scroll container is not directly accesible.

But we can get it with some simple math.

If this is our node structure:

—ScrollContainer
------Label

then we get the max of scroll horizontal with:

var scrollH_max = max(0, Label.rect_size.x - ScrollContainer.rect_size.x)

and of scroll vertical with:

var scrollV_max = max(0, Label.rect_size.y - ScrollContainer.rect_size.y)