[Control] Button Text Overflow when Assigning by Script
Tested versions
v4.3.stable.official [77dcf97d8]
System information
Godot v4.3.stable.mono - Windows 10.0.17763 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Ti (NVIDIA; 32.0.15.6109) - AMD Ryzen 9 5900X 12-Core Processor (24 Threads)
Issue description
The text will overflow when assigning the text property in the script.
Steps to reproduce
- Create a new project
- Create an empty
Controlscene, save it to a file, and mark it the main scene - Attach the MRP script to the root node
- Run the scene
Minimal reproduction project (MRP)
extends Control
func _ready():
var btn := Button.new();
btn.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
btn.autowrap_mode = TextServer.AUTOWRAP_WORD;
var vbox = VBoxContainer.new();
vbox.add_child(btn);
vbox.set_anchors_preset(Control.PRESET_FULL_RECT);
vbox.alignment = BoxContainer.ALIGNMENT_CENTER;
add_child(vbox);
Temporary Workaround:
Invoke the update_minimum_size next frame.
extends Control
var updated := false;
var btn : Button;
func _ready():
btn = Button.new();
btn.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
btn.autowrap_mode = TextServer.AUTOWRAP_WORD;
var vbox = VBoxContainer.new();
vbox.add_child(btn);
vbox.set_anchors_preset(Control.PRESET_FULL_RECT);
vbox.alignment = BoxContainer.ALIGNMENT_CENTER;
add_child(vbox);
func _process(_delta):
if updated : return;
updated = true;
btn.update_minimum_size();
Seems not related to assigning by script.
I can reproduce this with the text set in tscn as long as the Button's parent is a container, e.g., MarginContainer, VBoxContainer, PanelContainer etc.
CC @bruvzg
It seems that the button doesn't update the size of the text paragraph until it is drawn, but before that the container has been rearranged according to its get_minimum_size().