Document how to autoscroll ScrollContainer.

It is not uncommon to want to scroll to the most recently added child of
a ScrollContainer (e.g. a chat box or activity log). This is a little
tricky, since `ensure_control_visible` will not work on a node on the
same frame as you add it. Let's at least document that you need to wait
until the next frame.

Relates to https://github.com/godotengine/godot-proposals/issues/3629.

Backport of https://github.com/godotengine/godot/pull/55609.

Co-authored-by: Yuri Sizov <pycbouh@users.noreply.github.com>
(cherry picked from commit 22fb04bddf)
This commit is contained in:
Ryan Roden-Corrent 2021-12-03 19:07:01 -05:00 committed by Rémi Verschelde
parent 9d44a88e0b
commit 6a230c0cd3
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 6 additions and 0 deletions

View File

@ -14,6 +14,12 @@
<argument index="0" name="control" type="Control" />
<description>
Ensures the given [code]control[/code] is visible (must be a direct or indirect child of the ScrollContainer). Used by [member follow_focus].
[b]Note:[/b] This will not work on a node that was just added during the same frame. If you want to scroll to a newly added child, you must wait until the next frame using [signal SceneTree.idle_frame]:
[codeblock]
add_child(child_node)
yield(get_tree(), "idle_frame")
ensure_control_visible(child_node)
[/codeblock]
</description>
</method>
<method name="get_h_scrollbar">