Hi all,
Following scenario:
I have a box of size 100x100. I want to write text (label) inside this box. It may not extend the boundaries of the box, no matter how big the text is.
How I tried to achieve it:
Start with a font size of 64 and decrease it until it fits inside a box of 100x100 (checked using get_wordwrap_string_size())
onready var font_data = load("fonts/mayfont.ttf")
...
var dynamic_font = DynamicFont.new()
dynamic_font.font_data = font_data
dynamic_font.size = 64
while dynamic_font.get_wordwrap_string_size(text, 100).y > 100:
dynamic_font.size -= 1
var tmp_label = Label.new()
tmp_label.autowrap = true
tmp_label.rect_size = Vector2(128,128)
tmp_label.text = text
tmp_label.rect_position = coordinates
tmp_label.set("custom_fonts/font", dynamic_font)
tmp_label.set("custom_colors/font_color",Color(0,0,0))
ui.add_child(tmp_label)
Result:
The condition of the while loop is met, font size set to 32 -> it should fit but in reality it looks like this:

I hope you can help me. Thanks in advance