godot icon indicating copy to clipboard operation
godot copied to clipboard

[Control] Button Text Overflow when Assigning by Script

Open Delsin-Yu opened this issue 1 year ago • 3 comments

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.

image

Steps to reproduce

  1. Create a new project
  2. Create an empty Control scene, save it to a file, and mark it the main scene
  3. Attach the MRP script to the root node
  4. 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);

Delsin-Yu avatar Sep 23 '24 09:09 Delsin-Yu

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();

Delsin-Yu avatar Sep 23 '24 09:09 Delsin-Yu

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

timothyqiu avatar Sep 23 '24 09:09 timothyqiu

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().

zaevi avatar Sep 23 '24 11:09 zaevi