Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container size not updating correctly when using call_deferred #77885

Closed
Lippanon opened this issue Jun 5, 2023 · 2 comments · Fixed by #78009
Closed

Container size not updating correctly when using call_deferred #77885

Lippanon opened this issue Jun 5, 2023 · 2 comments · Fixed by #78009

Comments

@Lippanon
Copy link

Lippanon commented Jun 5, 2023

Godot version

543750a

System information

Windows 10, Vulkan

Issue description

This is a regression since v4.1.dev4.official [5c2295f], I can't bisect atm to find the commit that caused it, maybe #77651 but that's just a guess.
When a HBoxContainer has a label child, and that label's text is changed, one used to be able to find the new size of the container by using call_deferred, this is no longer the case.

MRP correct behavior (v4.1.dev4.official [5c2295f]):
image
MRP incorrect (543750a):
image

Steps to reproduce

extends Control

@onready var h_box_container: HBoxContainer = $HBoxContainer
@onready var label: Label = $HBoxContainer/Label

func _ready() -> void:
	label.text = "larger non default text"
	print("h_box_container size.x: ", h_box_container.size.x)
	call_deferred("size_after_text_changed")

func size_after_text_changed() -> void:
	print("deferred h_box_container size.x: ", h_box_container.size.x)

Minimal reproduction project

call_deferred bug.zip

@Rindbee
Copy link
Contributor

Rindbee commented Jun 6, 2023

The order of calls is this: label.set_text() => lable.update_minimum_size() => container.update_minimum_size() => container.size_changed.

update_minimum_size can be simply regarded as call_deferred("_update_minimum_size"). There are at least two deferred calls here.

The resized or minimum_size_changed signals can be used.

@Lippanon
Copy link
Author

Lippanon commented Jun 6, 2023

The resized or minimum_size_changed signals can be used.

Those can be a work-around in some cases, but they are only emitted if the size changes. One might want to do something like a dynamic code-driven animation that relies on the correct size after setting the text, without knowing if that text will force a resize ahead of time, which makes things difficult. await get_tree().process_frame is also not the same because of the 1-frame delay, seemingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants